Public Group

# Program crashes with DevIL (OpenIL)

This topic is 3692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So I've tried using DevIL to load images for my small OpenGL program. The program compiles fine, but each time I run it, the program crashes and it gives me one of those common windows error messages (the ones that asks whether you want to send an error report or not).. I tried debugging it in Visual C++, but and it gets stuck at the following errors
First-chance exception at 0x00000000 in 2dgame.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x00000000 in 2dgame.exe: 0xC0000005: Access violation reading location 0x00000000.


I've also tried using some of the .exe files from NeHe that uses OpenIL, but all of them causes the same error.. The error seems to occur when I use the ilLoadImage("lol.jpg") function, since everything works fine once I've taken it out, or change it to ilLoadImage(""). Here's my code, I've taken out some parts that are not related to OpenIL:
#include <gl\glut.h>
#include <IL\il.h>
#include <IL\ilu.h>
#include <IL\ilut.h>

GLuint	texture[2];

{
ILuint ImgId;
ilGenImages(1, &ImgId);
ilBindImage(ImgId);
ilDeleteImages(1, &ImgId);
return FALSE;
}

texture[1] = ilutGLBindTexImage();
ilDeleteImages(1, &ImgId);

return TRUE;
}

void InitIL()
{
ilInit();
iluInit();
ilutRenderer(ILUT_OPENGL);
}

void main(int argc, char **argv) {
InitGL();
...
}


Anyone know what is causing this problem? Sorry if this is a silly question.. I'm new to OpenGL and I'm not a very good programmer myself..

##### Share on other sites
If you're executing the code through VS (running in debug or whatever), make sure you set the project's Working Directory. lol.jpg should then be in that directory. If you're running the .exe directly, lol.jpg should be in the same directory as the .exe.

Also, from what I remember, ilLoadImage handles the gen and bind calls internally, and delete if it fails. Doesn't it?

##### Share on other sites
That exception means that you attempted to dereference a NULL pointer. If you check your variables when you break into the debugger, you should be able to find the pointer causing the problem (provided it breaks in code that you have the source code for).

##### Share on other sites
Quote:
 Original post by Interesting DaveIf you're executing the code through VS (running in debug or whatever), make sure you set the project's Working Directory. lol.jpg should then be in that directory. If you're running the .exe directly, lol.jpg should be in the same directory as the .exe.Also, from what I remember, ilLoadImage handles the gen and bind calls internally, and delete if it fails. Doesn't it?

i always made sure that the image files were in the same directory as the .exe file, so i dont think that would be the problem... besides, if ilLoadImage could not find the image, it should just return IL_FALSE rather then just crashing..

Quote:
 Original post by MJPThat exception means that you attempted to dereference a NULL pointer. If you check your variables when you break into the debugger, you should be able to find the pointer causing the problem (provided it breaks in code that you have the source code for).

after breaking, the only variables was ImgId, with a value of 0, and type as unsigned int. not sure what that means though...

##### Share on other sites
Quote:
 Original post by CustomDriveafter breaking, the only variables was ImgId, with a value of 0, and type as unsigned int. not sure what that means though...

It's referring to this:

ILuint ImgId;

you have that in your code. ILuint is clearly just a typedef to unsigned int, which is why it shows up that way in the debugger. What line of your code does the debugger break on?

##### Share on other sites
nevermind, i think i fixed the problem...
basically, i called on the function LoadGLTexture() before actually initializing DevIL (which is done in InitIL()).. the strange thing is, the code on NeHe's website is also written this way...

also, another problem that I have now is that ilLoadImage("lol.jpg") keeps failing (and returning false) for some odd reason. I'm pretty sure i have the files in the correct folder...

##### Share on other sites
By default your executable will be run in the folder your project is contained in, even though the actual executable is placed in the "Debug" or "Release" subfolder. Your texture should go in the same folder as your project.

##### Share on other sites
ok, seems like it's found the file..

another problem arises.. ilutGLBindTexImage(); keeps returning 0, which according to OpenIL's documentation means that an error has occurred.

EDIT: I've decided to post in the Alternative Library forum instead, since it seems more appropriate there.. thanks for the help!

[Edited by - CustomDrive on May 9, 2008 4:37:05 PM]

• 35
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631358
• Total Posts
2999531
×