10.6.8上Xcode中Cinder教程的早期部分出现getOpenFilePath错误

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

本文关键字:期部 错误 getOpenFilePath 教程 Xcode Cinder      更新时间:2023-10-16

我刚刚在运行OSX 10.6.8的Macbook Pro上下载了Cinder v0.8.4,并开始使用Xcode完成欢迎使用Cinder的第1章。我使用Tinderbox工具制作了一个名为CinderProjectApp的新项目,该项目具有默认选项。我还按照说明确保我的boost库与默认库(1.4.2)相同

当我开始学习教程时,我想看看是否可以从/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代码时,我会在指定文件路径的行上得到错误:从'boost::filesystem3::path'转换为非标量类型'std::basic_string,std::allocater>'请求。由于这在语法上是有效的,我想知道getOpenFilePath出了什么问题。

如果您需要查看代码的其余部分,请告诉我。顺便说一下,我在这里交叉提出了我的问题。

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

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