C++DevIL函数ilLoadImage-程序退出,访问违规
C++ DevIL function ilLoadImage - program exit, access violation
我有一个这样定义的文件路径:
const char* GROUND_TEXTURE_FILE = "objects/textures/grass.jpg";
这是我用来加载图像的函数:
bool loadTexImage2D(const string &fileName, GLenum target) {
...
// this will load image data to the currently bound image
// at first, we must convert fileName, for ascii, this method is fine?
wstring file(fileName.begin(), fileName.end());
if(ilLoadImage(file.c_str()) == IL_FALSE) { //here the program falls
我的代码出了什么问题?调用ilLoadImage
时程序为什么会失败?我认为,file.c_str()
作为wchar_t *
类型是否应该正常工作?感谢回答:)
正如作者所说,您可以在不初始化lib:D的情况下做任何事情
#include <iostream>
#include <IL/il.h>
int main ()
{
std::string filename = "objects/textures/grass.jpg";
ilInit();
if (!ilLoadImage(filename.c_str())) {
std::cout << ilGetError() << std::endl;
return 1;
}
std::cout << ilGetInteger(IL_IMAGE_WIDTH) << std::endl;
std::cout << ilGetInteger(IL_IMAGE_HEIGHT) << std::endl;
return 0;
}
构建:
g++ -Wall -pedantic --std=c++11 -g -o app main.cpp -lIL
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 通过方法访问结构
- 使用不带参数的函数访问结构元素
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 用于访问容器<T>数据成员的正确 API
- 访问者访问变体并返回不同类型时出错
- 尝试通过多个向量访问变量时,向量下标超出范围
- 无法访问嵌套类.类的使用无效
- 写入位置0x0000000C时发生访问冲突
- 我们可以访问一个不存在的联盟的成员吗
- C++从另一个类访问公共静态向量的正确方法是什么
- 我的简单if-else语句是如何无法访问的代码
- 从C++dll访问C#中的一行主要参数
- 概念TS检查忽略私有访问修饰符
- 无法访问 Arduino 结构字段。错误"退出状态 1。xxxx 不命名类型"
- 进程退出,返回值3221225477访问多维向量
- C++DevIL函数ilLoadImage-程序退出,访问违规
- 是否可以进行编译,以使错误的std::vector访问调用退出程序,并显示有用的错误消息
- 在C++中使用Box2D物理退出游戏时出现访问冲突错误
- 线程在主线程退出后访问共享变量