• Advertisement
Sign in to follow this  

Crash calling SOIL_load_image

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to use SOIL (Simple OpenGL Image Library) to load images in my project.  However, it is crashing whenever I call SOIL_load_image, from an unhandled exception writing location 0x00000014.  (I'm following this tutorial, btw: http://open.gl/textures).  

 

I'm unsure of what I can do to fix this issue, but I think its something related to how I'm setting up the library.  Yesterday, I was trying to do something similar with libPNG and was running into a similar crash when the library attempted to do some file IO.  At the time, I thought it was probably an issue with the library, but now that I'm getting another crash with a different library, I think it might be me.

 

For the SOIL library, I built the project and copied the debug SOIL.lib to my VC/lib directory, and SOIL.h to the VC/include directory.  It seems to be building fine, but is crashing.  I tried it with the release .lib as well and the same thing happens.

 

Where I'm trying to load the image (GLTextureFactory.cpp):

#include "GLTextureFactory.h"

#pragma comment(lib, "SOIL")

#include <SOIL.h>

#include "GLTexture.h"

GLTextureFactory::GLTextureFactory(void)
{

}

GLTextureFactory::~GLTextureFactory(void)
{

}

GLTexture *GLTextureFactory::createTextureForImage(const char *imageFilename)
{
    int width, height;

    //CRASHING ON THIS LINE
    unsigned char* image = SOIL_load_image(imageFilename, &width, &height, 0, SOIL_LOAD_RGB);
    
    //glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image );

    return new GLTexture(0);
}

 

I have included GLM in my project, and am also linking against:
#pragma comment(lib, "GLFW")
#pragma comment(lib, "opengl32")
#pragma comment(lib, "glu32")
#pragma comment(lib, "glew32")
 
Any help is very appreciated!
Edited by scottrick49

Share this post


Link to post
Share on other sites
Advertisement

Where is GLTextureFactory::createTextureForImage() being called?

Share this post


Link to post
Share on other sites

Its getting called after my OpenGL context is created.  I don't think that's related to the problem, though, since I'm not actually doing anything OpenGL related in here. (yet).

Share this post


Link to post
Share on other sites

Ah, I forgot to mention, I'm getting one build warning, but I'm not sure how to fix it, or if its even relevant:

1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

Share this post


Link to post
Share on other sites

Its getting called after my OpenGL context is created.  I don't think that's related to the problem, though, since I'm not actually doing anything OpenGL related in here. (yet).

It might be related. If filename is invalid, it could cause a crash. Try posting a minimal example that still exhibits the problem. If at any point after your remove something that isn't necessary and the problem goes away, investigate that.

Share this post


Link to post
Share on other sites

Hmm, I was able to fix the issue.  Evidently the order and/or location of all the #pragma comment(lib, "lib") makes a difference.  I put them all together in a different file and all is well.  I tried putting them all in my main.cpp, but that didn't work.  Not sure why.  Thanks for the help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement