2

Please take a look at the results of my first day VC++. It contains an error which I am aware about. My problem is that devil comes up with an error as it should be, but trying to decode this error to a string using iluErrorString() causes an access violation...

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

It coughs up an error 1285 meaning it doesn't understand this:

ilLoadL(IL_PNG, Lump, fileSize);

This I am aware of. The problem is here:

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

This causes an accesss violation and I can't figure out why?

2 Answers2

3

This problem occurs if you haven't initialized ILU as you did for IL:

iluInit();
lnstadrum
  • 550
  • 3
  • 15
0

It is because iluErrorString always returns 0 as does ilGetString.

nwp
  • 9,623
  • 5
  • 38
  • 68
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – Mansfield Oct 02 '13 at 12:53
  • How does this not answer the question? The return value of iluErrorString(error) is 0, which is passed to cout, which crashes as a result. – nwp Oct 09 '13 at 11:28
  • It is not sufficiently detailed and would be better as a comment unless it is improved. – Mansfield Oct 09 '13 at 12:30