glfwReadImage() crash

nobody wrote on Wednesday, March 17, 2004:

GLFWimage *pointer1;
const char name[] = "pointer1.tga";
/* ERROR */ if( ( glfwReadImage ( name, pointer1, GLFW_NO_RESCALE_BIT ) ) == GL_TRUE );

This compiles fine but crashes the program. If I use glfwLoadTexture2D() (which is not what I want :P) it doesn’t crash, so I guess the image i’m using is fine, right?

marcus256 wrote on Wednesday, March 17, 2004:


Looking into it…

marcus256 wrote on Wednesday, March 17, 2004:

Uhm. Silly error. You need to do this:

GLFWimage pointer1;
const char name[] = "pointer1.tga";
if( ( glfwReadImage ( name, &pointer1, GLFW_NO_RESCALE_BIT ) ) == GL_TRUE );

"pointer1" must be a valid memory area - glfwReadImage does not create the GLFWimage stuct for you, it simply fills out its fields. Also, do not forget to call glfwFreeImage once you are done with your image.

nobody wrote on Thursday, March 18, 2004:

Ahhh cool it’s solved now. Thanks man! What a quick response :slight_smile: Keep up the good work!

//here’s the code that works. Just added a line to allocate memory for the GLFWimage structure :slight_smile:
GLFWimage *pointer1;
pointer1 = new GLFWimage;
const char name[] = “pointer1.tga”;
glfwReadImage ( name, pointer1, GLFW_NO_RESCALE_BIT );

nobody wrote on Tuesday, October 30, 2007:

GLuint gl_textures[MAX_TEXTURES];
GLFWimage img[256];

if (!glfwReadImage("file.tga", &img[ID], 0))
printf("glfwReadImage(): failed; file: "%s"\n", file);

nobody wrote on Saturday, April 19, 2008:

thanks this was also my Problem. I think it would be usefull to put this information in the reference manual.

zacs7 wrote on Sunday, May 11, 2008:

What? Teach you C/C++ as-well?

Did you expect glfwReadImage() to allocate memory for you also? It doesn’t say that it does. It expects a pointer to a GLFWimage struct. It’s labeled as ‘in’ not ‘out’.

Love GLFW, keep up the good work.

elmindreda wrote on Sunday, May 11, 2008:

Please don’t bite people, it improves neither code nor mood.

nobody wrote on Monday, May 12, 2008:

He didn’t bite…

I agree it’s implicit, regardless it’s not a GLFW issue.