Jump to content
  • Advertisement
Sign in to follow this  
squizm

OpenGL SOIL causing access violation

This topic is 2707 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

HELP!

I'm attempting to use SOIL to load the JPGs for my openGL program. I'm compiled my own SOIL.lib and included it in the Visual Studio 2010 additional dependencies, and copy and included SOIL.h. However, at runtime I get an access violation from the following line:


tex_Dirt = SOIL_load_OGL_texture("dirt.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS);



Anyone ever run into this before? What other information can I provide to help diagnose this?

EDIT:

I set a break point on that line and followed it through SOIL.c. Turns out it causes the access violation at the following line:



/* OK, make it a texture! */
tex_id = SOIL_internal_create_OGL_texture(
img, width, height, channels,
reuse_texture_ID, flags,
GL_TEXTURE_2D, GL_TEXTURE_2D,
GL_MAX_TEXTURE_SIZE );

Share this post


Link to post
Share on other sites
Advertisement
Can you narrow it down further to the line of code that's actually causing the violation? Also, are you creating the textures after a valid OpenGL context has been created?

Share this post


Link to post
Share on other sites

Can you narrow it down further to the line of code that's actually causing the violation? Also, are you creating the textures after a valid OpenGL context has been created?


the function I posted above (SOIL_internal_create_ogl_texture) appears to run just fine until the following line:



if( (query_NPOT_capability() == SOIL_CAPABILITY_NONE) &&
!(flags & SOIL_FLAG_TEXTURE_RECTANGLE) )
{
/* add in the POT flag */
flags |= SOIL_FLAG_POWER_OF_TWO;
}



Stepping into that function is opens 'strstr.asm' and gets the violation on the exact line:


mov al,[edi] ; al is next char from str1



As for the openGL context, I am pretty new to openGL and completely self taught. The loading of the textures is down in my custom initGL() function:



GLvoid initGL(GLsizei width, GLsizei height)
{
glViewport(0,0,width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 200.0f);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_PERSPECTIVE_CORRECTION_HINT);
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);

//Create Screens
screens[MENU_SCREEN] = &menuScreen;
screens[GAME_SCREEN] = &playScreen;

//create Textures
GLuint tex_Dirt;
tex_Dirt = SOIL_load_OGL_texture("dirt.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS);
}




and the main function looks like this:



int main(int argc, char* argv[])
{
// Init glut
glutInit(&argc, argv);

initGL(windowWidth, windowHeight);

glutInitDisplayMode(GLUT_DOUBLE);
int windowID = glutCreateWindow("myGame");
glutReshapeWindow(windowWidth, windowHeight);
glutDisplayFunc(drawScene);
glutKeyboardFunc(keyboardCB);
glutKeyboardUpFunc(keyboardUpCB);
glutSpecialFunc(keyboardSpecialCB);
glutSpecialUpFunc(keyboardSpecialUpCB);
glutTimerFunc(1, timerLoop, 0);
glutMouseFunc(updateMouse);
glutMotionFunc(mouseMove);
glutPassiveMotionFunc(mouseMove);

glutMainLoop();
}

Share this post


Link to post
Share on other sites
I'm not sure how GLUT works with respect to creating the OpenGL context - is the context created in glutInit(), or in (e.g.) glutInitDisplayMode()?

I'm sure someone else will know the answer to that question, but meanwhile you might check the docs and see if you can determine it yourself. (The OpenGL initialization code needs to be run *after* a valid context is created; otherwise, run-time errors can occur.)

Share this post


Link to post
Share on other sites

I'm not sure how GLUT works with respect to creating the OpenGL context - is the context created in glutInit(), or in (e.g.) glutInitDisplayMode()?

I'm sure someone else will know the answer to that question, but meanwhile you might check the docs and see if you can determine it yourself. (The OpenGL initialization code needs to be run *after* a valid context is created; otherwise, run-time errors can occur.)

The rendering context is created in glutCreateWindow.

Share this post


Link to post
Share on other sites

[quote name='jyk' timestamp='1303935063' post='4803706']
I'm not sure how GLUT works with respect to creating the OpenGL context - is the context created in glutInit(), or in (e.g.) glutInitDisplayMode()?

I'm sure someone else will know the answer to that question, but meanwhile you might check the docs and see if you can determine it yourself. (The OpenGL initialization code needs to be run *after* a valid context is created; otherwise, run-time errors can occur.)

The rendering context is created in glutCreateWindow.
[/quote]


That was the issue. I created a function to load my textures after the glutCreateWindow call and it works like a champ. Thanks again for all your help.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!