c++ - 魔鬼 iluErrorString() 导致访问冲突

标签 c++ access-violation devil

请看一下我第一天VC++的结果。它包含一个我知道的错误。我的问题是,devil 出现了一个应该出现的错误,但是尝试使用 iluErrorString() 将此错误解码为字符串会导致访问冲突...

#pragma comment(lib, "ILU.lib")
#pragma comment(lib, "ILUT.lib")

#include <iostream>
#include <conio.h>
#include <stdio.h>

#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>

using namespace std;

int main(){
FILE *myFile;
ILuint fileSize;
ILubyte *Lump;

ilInit();

ILuint ImageName; // The image name to return.
ilGenImages(1, &ImageName); // Grab a new image name.

ilBindImage(ImageName); //bind the image

myFile = fopen("C:/Documents and Settings/Bartjan/Desktop/c++ meuq/test/Debug/image.png", "r"); //open the file for reading
if (myFile != NULL){
    fseek(myFile, 0, SEEK_END); //get file size
    fileSize = ftell(myFile);

    Lump = (ILubyte*)malloc(fileSize); //allocate mem
    fseek(myFile, 0, SEEK_SET); //set the file pointer
    fread(Lump, 1, fileSize, myFile); //read the entire file into mem

    fclose(myFile);

    ilLoadL(IL_PNG, Lump, fileSize);
    free(Lump);
}

ilDeleteImages(1, &ImageName); //delete the image

ILenum error;
while ((error = ilGetError()) != IL_NO_ERROR) {
    cout << error << ": " << iluErrorString(error);
}

_getch();
return 0;
}

它会抛出错误 1285,这意味着它不理解这一点:

ilLoadL(IL_PNG, Lump, fileSize);

这个我知道。问题出在这里:

cout << error << ": " << iluErrorString(error);

这会导致访问冲突,但我不明白为什么?

最佳答案

如果您没有像对 IL 那样初始化 ILU,则会出现此问题:

iluInit();

关于c++ - 魔鬼 iluErrorString() 导致访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15507321/

相关文章:

c# - 媒体基础 : ReadSample - Access Violation Exception

c++ - 将结构覆盖到 u_char 指针上

c++ - C++ 中的二维 vector 数组

c++ - 删除数组时出现访问冲突异常

string - Delphi:将字符串放入编辑框中时出现访问冲突?

c++ - 如何从原始数据加载 devIL 图像

c++ - 不能用 devIL 调用任何函数

c++ - 使用 DevIL 在 C++ OpenGL 中加载纹理

c++ - 如何检测 C++ 中未分配内存的双重删除或删除?

c++ - 使用 #define 指令作为代码的 "part",而不是在文件顶部