2013-02-05 21 views
0

我刚刚在运行OSX 10.6.8的Macbook Pro上下载了Cinder v0.8.4,并开始使用Xcode的欢迎使用Cinder的第1章。我用Tinderbox工具用默认选项创建一个名为CinderProjectApp的新项目。我也按照说明来确保我的boost库与默认(1.4.2)相同。getOpenFilePath在Xcode的Cinder教程的早期部分出现错误10.6.8

当我开始学习本教程时,我想看看是否可以从/ resources文件夹加载自己的图像,因此我下载了一个图像“Broccoli.jpg”并将其添加到我的CinderProjectApp/resources /目录。

这里是我的draw()函数:

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()); 
} 

当我编译我的小CinderProjectApp.cpp代码全部,我得到错误:转换,从“提高:: filesystem3 ::路径”非-scalar type'std :: basic_string,std :: allocator>'请求在我指定文件路径的行上。由于这在句法上是有效的,所以我想知道getOpenFilePath发生了什么问题。

如果您需要查看代码的其余部分,请告诉我。顺便说一句,我转发了我的问题here

回答

2

感谢Paul and Sansumbrella’s help在forum.libcinder.org上,我将try-catch移动到setup函数(为了提高效率),并使用ci :: fs :: path对象来保存路径。这里是我的新setup()函数(假设除了try-catch逻辑的重新排序外,上面draw()中的所有内容都不变):

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; 
    } 
}