10.6.8上Xcode中Cinder教程的早期部分出现getOpenFilePath错误
getOpenFilePath error in early part of Cinder tutorial in Xcode on 10.6.8
我刚刚在运行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;
}
}
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 尝试从深度图像中提取手部轮廓时出现无效矩阵错误