# glfwReadImage() crash

**URL:** https://discourse.glfw.org/t/glfwreadimage-crash/466
**Category:** support
**Created:** [March 17, 2004, 7:33pm UTC](https://discourse.glfw.org/t/glfwreadimage-crash/466 "2004-03-17T19:33:31Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)
#### Post date: [March 17, 2004, 7:33pm UTC](https://discourse.glfw.org/t/glfwreadimage-crash/466/1 "2004-03-17T19:33:31Z")

</div>

**nobody** wrote on [Wednesday, March 17, 2004](https://sourceforge.net/p/glfw/discussion/247562/thread/2c4e564b/#87b2):

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?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)
#### Post date: [March 17, 2004, 8:45pm UTC](https://discourse.glfw.org/t/glfwreadimage-crash/466/2 "2004-03-17T20:45:02Z")

</div>

**[marcus256](https://sourceforge.net/u/marcus256/)** wrote on [Wednesday, March 17, 2004](https://sourceforge.net/p/glfw/discussion/247562/thread/2c4e564b/#87b2/508e):

Hello!

Looking into it…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)
#### Post date: [March 17, 2004, 8:52pm UTC](https://discourse.glfw.org/t/glfwreadimage-crash/466/3 "2004-03-17T20:52:37Z")

</div>

**[marcus256](https://sourceforge.net/u/marcus256/)** wrote on [Wednesday, March 17, 2004](https://sourceforge.net/p/glfw/discussion/247562/thread/2c4e564b/#87b2/b142):

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)
#### Post date: [March 18, 2004, 8:04am UTC](https://discourse.glfw.org/t/glfwreadimage-crash/466/4 "2004-03-18T08:04:52Z")

</div>

**nobody** wrote on [Thursday, March 18, 2004](https://sourceforge.net/p/glfw/discussion/247562/thread/2c4e564b/#87b2/f235):

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

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)
#### Post date: [October 30, 2007, 4:13pm UTC](https://discourse.glfw.org/t/glfwreadimage-crash/466/5 "2007-10-30T16:13:46Z")

</div>

**nobody** wrote on [Tuesday, October 30, 2007](https://sourceforge.net/p/glfw/discussion/247562/thread/2c4e564b/#9a34):

GLuint gl\_textures[MAX\_TEXTURES];  
GLFWimage img[256];

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)
#### Post date: [April 19, 2008, 3:48pm UTC](https://discourse.glfw.org/t/glfwreadimage-crash/466/6 "2008-04-19T15:48:02Z")

</div>

**nobody** wrote on [Saturday, April 19, 2008](https://sourceforge.net/p/glfw/discussion/247562/thread/2c4e564b/#f730):

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)
#### Post date: [May 11, 2008, 5:40am UTC](https://discourse.glfw.org/t/glfwreadimage-crash/466/7 "2008-05-11T05:40:59Z")

</div>

**[zacs7](https://sourceforge.net/u/zacs7/)** wrote on [Sunday, May 11, 2008](https://sourceforge.net/p/glfw/discussion/247562/thread/2c4e564b/#619a):

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)
#### Post date: [May 11, 2008, 11:27am UTC](https://discourse.glfw.org/t/glfwreadimage-crash/466/8 "2008-05-11T11:27:13Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Sunday, May 11, 2008](https://sourceforge.net/p/glfw/discussion/247562/thread/2c4e564b/#619a/f38d):

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)
#### Post date: [May 12, 2008, 4:14am UTC](https://discourse.glfw.org/t/glfwreadimage-crash/466/9 "2008-05-12T04:14:30Z")

</div>

**nobody** wrote on [Monday, May 12, 2008](https://sourceforge.net/p/glfw/discussion/247562/thread/2c4e564b/#918a):

He didn’t bite…

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