开发者

Memory error using OpenGL "glTexImage2D"

I've been following this tutorial on OpenGL and C++: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06

...and 开发者_JAVA技巧I've found myself facing quite the error. Whenever I try to compile, my program crashes with an error of the type, System.AccessViolationException. I've isolated the problem to be in this function:

glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

In case you don't want to look through that tutorial, the memory appears to be set up like so:

AUX_RGBImageRec *TextureImage[1];
memset(TextureImage,0,sizeof(void *)*1);

Any help would be awesome. Thanks.


You're crashing because TextureImage[0] is NULL. The initial memset there sets it to NULL; if you follow along in the tutorial, the next line of code is this:

if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))

Note carefully that there is a single = sign here, not a double == as you'd normally see (you may even get a compiler warning here; to suppress that, add extra parentheses around the assignment)). Make sure you copied this line of code correctly and that you have a single = here.

If in fact you do have a single =, then check to make sure that LoadBMP is returning a non-NULL value. If it's returning NULL, the most likely cause is that it can't find the bitmap file Data/NeHe.bmp, either because it doesn't exist or it's looking for it in the wrong directory. Make sure your current working directory is set up correctly so that it can find the image.


Turns out the bitmap I was trying to load was too large. I shrunk it to 256x256px and it worked perfectly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜