bool loadTexture(char* file_name, char* tex_name, _Texture_List &tex_list)
{
for(int i = 0; i < tex_list.num_textures; i++)
if(strcmp(tex_name, tex_list.names) == 0)
return false;
tex_list.textures = (GLuint*)realloc(tex_list.textures, sizeof(GLuint) * (tex_list.num_textures + 1));
SDL_Surface* bmp_file = SDL_LoadBMP(file_name);
if(bmp_file == NULL)
{
cout << "Error loading " << tex_name << ":" << endl;
cout << SDL_GetError() << endl;
return false;
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &tex_list.textures[tex_list.num_textures]);
glBindTexture(GL_TEXTURE_2D, tex_list.textures[tex_list.num_textures]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D,3,bmp_file->w, bmp_file->h,GL_BGR_EXT,
GL_UNSIGNED_BYTE, bmp_file->pixels);
SDL_FreeSurface(bmp_file);
tex_list.num_textures++;
return true;
}
Can't run executable SDL textures likely source
I have a texture loading function:
Nothing elegant, the majority of the code is modeled after a steinsoft tutorial, I believe. The textures get loaded properly and look fine when I use them, but only when I run the program from Visual Studio (it works in both debug and release mode). If I attempt to run the program from the executable, however, it crashes at the call to SDL_FreeSurface. This suggests that the surface pointer is accessing data it is not allowed to (and is not allowed to free), but I don't see how. If it were pointing to some other piece of data, why would the textures be drawing properly? SDL reports no errors, even if I print out SDL_GetError just before the call to SDL_FreeSurface. It's a bit strange.
Any suggestions?
It's never being loaded. It can't find the file. When you run from visual studio, the working directory is the where the project file is, not where the exe is.
I thought about that, but moving the exe to where the project file is doesn't help. That should clear it up if that were the issue, no? And also, SDL is reporting no errors even right before the problematic function call, which is most assuredly would if the file were never found...
Quote:Original post by Deyja
Are you sure you're detecting the error properly?
Normally, I check to see if the surface is equal to NULL, and if it is, report the error. It doesn't report an error this way, but as there's a problem, I also just have it output the last error before the line of problematic code to be sure:
cout << "Error: " << SDL_GetError() << endl;
SDL_FreeSurface(bmp_file);
The only thing that gets printed out is "Error: ", implying SDL has detected no errors.
How about compiling it as debug, and then run the debug version outside of VS? You can attach the debugger then and see how it runs and what goes wrong.
Also, before you attempt to do this, make sure your application waits at least 60 seconds before proceeding(So you have the time to attach the debugger).
Toolmaker
Also, before you attempt to do this, make sure your application waits at least 60 seconds before proceeding(So you have the time to attach the debugger).
Toolmaker
Well I've already debugged the thing after it crashes, and it points to the line SDL_FreeSurface(bmp_file);. Are you suggesting I attach the debugger so I can look at things prior to that line before it crashes? If so, how exactly do I attach the debugger to the executable? Just run the executable in the debug folder? If so, that's what I have been doing.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement