SDL Bitmap loading problems

Started by
5 comments, last by CyberSlag5k 18 years, 9 months ago
I'm doing texturing using a function I wrote to utilize SDL's bitmap loading functionality. However, for certain bitmaps, it blows up when I call SDL_FreeSurface, saying there was an access violation. What's weird it'll work for one bitmap that's 256x256 and something like 150KB, but it won't for another that's 256x256 that's only like 60KB. I didn't think bitmaps were compressed at all, but the fact that they're the same dimensions and different sizes suggests different compressions or different DPI resolutions or something. I don't think I'm doing anything particularly wrong in the code:

	SDL_Surface* bmp_file = SDL_LoadBMP(file_name);
	if(bmp_file == NULL)
	{
		cout << "Error: ";
		for(int i = 0; i < strlen(SDL_GetError()); i++)
			cout << (SDL_GetError());
		cout << endl;
		return false;
	}
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

	glGenTextures(1, &tex_list.textures[tex_list.count]);
	glBindTexture(GL_TEXTURE_2D, tex_list.textures[tex_list.count]);
	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);


What's peculiar is the Error is never reported. It just blows up. Can anyone see what I might be doing wrong?
Without order nothing can exist - without chaos nothing can evolve.
Advertisement
I don't know why this would affect your code, but do you know what the bit depths are for your two diffrent BMPs?
Ahh, that was it. The one that didn't work was a 256 color bitmap. Converting it to 24 bits worked just fine.

Thanks, SiCrane. [smile]
Without order nothing can exist - without chaos nothing can evolve.
I'm sorry to OT but I was very curious as to why you do this:

for(int i = 0; i < strlen(SDL_GetError()); i++)    cout << (SDL_GetError());


Would you mind explaining? [grin]
Quote:Original post by clockwise
I'm sorry to OT but I was very curious as to why you do this:

*** Source Snippet Removed ***

Would you mind explaining? [grin]


Certainly. SDL_GetError() returns the last error reported by SDL. It's returned as a character array (char *), so to print it I loop until the end of the array (i < the length of the string), printing each character along the way. I don't work with character arrays too often (I prefer the string class), so I don't know of a better way. If someone would like to suggest one (you can't just cout, can you?), I'd be most interested to hear it.

Hope that answers your question, clockwise.
Without order nothing can exist - without chaos nothing can evolve.
Unless you have a strange and broken compiler, or aren't including the right header files, you should just be able to cout << SDL_GetError().
Quote:Original post by SiCrane
Unless you have a strange and broken compiler, or aren't including the right header files, you should just be able to cout << SDL_GetError().


Nah, jus a strange and broken mind.

I don't know why, but I've always just assumed you couldn't do that and have always output my character arrays. Not sure where I got the notion from, nor why I've never really tried using the insertion operator.

Ahh the little stuff I should probably know [smile]. Thanks agian, SiCrane.
Without order nothing can exist - without chaos nothing can evolve.

This topic is closed to new replies.

Advertisement