Search code examples
c++xcodeboostosx-snow-leopardcinder

getOpenFilePath error in early part of Cinder tutorial in Xcode on 10.6.8


I just downloaded Cinder v0.8.4 on my Macbook Pro running OSX 10.6.8, and started working through Chapter 1 of Welcome to Cinder using Xcode. I used the Tinderbox tool to make a new project called CinderProjectApp with default options. I also followed the instructions to ensure that my boost library is the same as the default (1.4.2).

As I began working through the tutorial, I wanted to see if I could load my own image from the /resources folder, so I downloaded an image "Broccoli.jpg" and added it to my CinderProjectApp/resources/ directory.

Here is my draw() function:

void CinderProjectApp::draw()
{
    gl::clear( Color( 0, 0, 0 ), true );

    try
    {    
        std::string p = FilePath( "", ImageIo::getLoadExtensions() );    

        if( ! p.empty() ) 
        { // an empty string means the user canceled    
            myImage = gl::Texture( loadImage( p ) );
        }
    }

    catch( ... ) 
    {
        console() << "Unable to load the image." << std::endl;
    }

    gl::draw(myImage, getWindowBounds());
}

When I compile the entirety of my small CinderProjectApp.cpp code, I get error: conversion from 'boost::filesystem3::path' to non-scalar type 'std::basic_string, std::allocator >' requested on the line where I specify the path to the file. Since this appears syntactically valid, I’m wondering what’s going wrong here with getOpenFilePath.

If you need to see the rest of the code, please let me know. By the way, I crossposted my question here.


Solution

  • Thanks to Paul and Sansumbrella’s help at forum.libcinder.org, I’ve moved my try-catch to the setup function (for efficiency), and used the ci::fs::path object to hold the path. Here is my new setup() function (assume that everything in draw() from above is unchanged besides the reordering of the try-catch logic):

    void CinderProjectApp::setup()
    {
    
        try 
        {   
            ci::fs::path p = getOpenFilePath( "", ImageIo::getLoadExtensions());
    
            if( ! p.empty() ) 
            { // an empty string means the user canceled
                myImage = gl::Texture( loadImage( p ) );
            }
        }
    
        catch( ... ) 
        {
            console() << "Unable to load the image." << std::endl;
        }
    }