Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


unhandled exception when loading images


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Ussyless   Members   -  Reputation: 142

Like
0Likes
Like

Posted 13 August 2012 - 08:41 PM

so currently, i have 2 classes that load images directly.
class 1:
Spritesheet; loads images, able to take a sprite off it from a grid and a set size and put into a texture class.
Texture; loads images, accepts sprites from grid of spritesheet


the problem is, after setting up a sprite-get from the spritesheet class, all loads from the texture class throw an unhandled exception/ access violation

the function causing the problem is as follows:

GLuint g_spritesheet::getsprite(unsigned short x,unsigned short y)
{
glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, x*gridsize);
    glPixelStorei(GL_UNPACK_SKIP_ROWS, y*gridsize);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, w);

GLuint tex;
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glGenTextures(1,&tex);
    glBindTexture(GL_TEXTURE_2D,tex);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, 4, gridsize, gridsize, 0,GL_RGBA, GL_UNSIGNED_BYTE, data);
    return tex;
glPopClientAttrib();
}


and when i remove
"
glPixelStorei(GL_UNPACK_SKIP_PIXELS, x*gridsize);
glPixelStorei(GL_UNPACK_SKIP_ROWS, y*gridsize);
glPixelStorei(GL_UNPACK_ROW_LENGTH, w);" the error stops occuring.
so how can i reset these after using them? i thought glpushclientattrib/pop would work, but it doesnt.

also, if needed, this is the texture loading function

void g_texture::load(char* filename)
{
loaded=0;
ilGenImages(1, &iltex);
ilBindImage(iltex);
bool success=0;
success=ilLoadImage(filename);
if (success)
{
  success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
  if (!success)
  {
   printf("error converting: ");
   printf((char*)iluErrorString( ilGetError()));
   printf("\n");
  }
  else
  {
   loaded=1;
  }
}
else
{
  printf("error: ");
  printf((char*)iluErrorString( ilGetError()));
  printf("\n");
}
if (loaded)
{
  GLuint tex;
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  glGenTextures(1,&tex);
  glBindTexture(GL_TEXTURE_2D,tex);
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  w=ilGetInteger(IL_IMAGE_WIDTH);
  h=ilGetInteger(IL_IMAGE_HEIGHT);
  glTexImage2D(GL_TEXTURE_2D, 0, 4, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0,GL_RGBA, GL_UNSIGNED_BYTE, ilGetData());
}
}

using breakpoints im pretty sure glteximage2d is the thing throwing the exception.
i wrote these a while ago so they are probably a little messy, but thats not my concern at the moment, anyway, any help?

Sponsor:

#2 Freya   Members   -  Reputation: 804

Like
0Likes
Like

Posted 14 August 2012 - 06:59 AM

Do you by any chance use several threads in your application?

I've been using Irrlicht (w/OpenGL), and when I set up the driver and device and then made textures on an other thread, I got very obscure errors. I think this is probably an issue with the driver (nVidia) or OpenGL, not Irrlicht itself.

If you're using multiple threads, try to set up OpenGL and load textures on the same thread.
Working on a game "Burnt islands".
Dev blog       
"Burnt islands" on Indie DB

#3 hentailoli   Members   -  Reputation: 185

Like
0Likes
Like

Posted 14 August 2012 - 07:21 AM

Hmm I am not entirely sure that if the reason is multiple threads the code will crash. I usually get a GL_INVALID_OPERATION. Why don't you actually check if DeviL is loading the file correctly. By that I mean check the raw data. Also try to use DeviL's functions for loading textures to OpenGL.

Edited by Solano, 14 August 2012 - 07:21 AM.


#4 Waterlimon   Crossbones+   -  Reputation: 2596

Like
0Likes
Like

Posted 14 August 2012 - 07:28 AM

Or you can just try to switch to FreeImage, as i think DevIL is kind of old and not being maintained... I set up DevIL but switched to freeimage the next day as it felt a bit fresher...

o3o


#5 Ussyless   Members   -  Reputation: 142

Like
0Likes
Like

Posted 14 August 2012 - 10:04 AM

i have looked, and it appears to load the raw image data, i only get the error if
glPixelStorei(GL_UNPACK_SKIP_PIXELS, x*gridsize);
glPixelStorei(GL_UNPACK_SKIP_ROWS, y*gridsize);
glPixelStorei(GL_UNPACK_ROW_LENGTH, w);
is present in the spritesheet class, and its used before i load a texture, leading me to believe that glpushclientstate and pop arent doing what i want them to do (save the default state and reload it after)

however i do need that for it to work
also no i'm not using multiple threads at the moment

any help?

Edited by Ussyless, 14 August 2012 - 09:35 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS