Skip to main content
GameDev.net gamedev.net
๐Ÿ”’ Locked

glTexImage2D - segfault

Started by jeannekamikaze Jun 2, 2010 at 3:38 AM 1 replies 4k views
Original Post
jeannekamikaze
jeannekamikaze
Hello, I am having some trouble with glTexImage2D. What happens is it segfaults every now and then (about 9 out of 10 times). This is what I am doing essentially:

GLuint ID;
char data[64*64];

glEnable(GL_TEXTURE_2D);
glGenTextures(1, &ID);
glBindTexture(GL_TEXTURE_2D, ID);

// Segfault here -->
glTexImage2D(GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
// <--

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

...

I am checking for errors with glGetError() after glEnable, glGenTextures, and glBindTexture, and no errors turn up.

Could anyone provide any light as to what might cause the problem?
Thanks in advance.
rewolfer
rewolfer
You have specified to glTexImage2D to have 4 components per colour value, that's 64*64*4 bytes. Yet the char array you created only has enough for a byte per texel.
jeannekamikaze
jeannekamikaze
Ah! Thanks. Lots of happiness for you and your loved ones :).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.