Can't run executable SDL textures likely source

Recommended Posts

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[i]) == 0)
return false;

tex_list.textures = (GLuint*)realloc(tex_list.textures, sizeof(GLuint) * (tex_list.num_textures + 1));

if(bmp_file == NULL)
{
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;
}


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?

Share on other sites
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.

Share on other sites
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...

Share on other sites
Are you sure you're detecting the error properly?

Share on other sites
Quote:
 Original post by DeyjaAre 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.

Share on other sites
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

Share on other sites
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.

Share on other sites
assuming msvc

debug->processes, choose the running process, attach

Create an account

Register a new account

• Forum Statistics

• Total Topics
627711
• Total Posts
2978761

• 21
• 14
• 12
• 41