Page 1 of 3

SDL problem

Posted: Mon May 31, 2010 4:07 pm
by Avishaiozeri
Hi guys, i need your help. i'm beginning with SDL now...
I loaded an img using SDL_LoadBMP, and before blitting it to the screen i converted it to the screen->format using SDL_ConvertSurface, But it crashes! it compiles okay, and when i run it through the project folder it runs fine, but when i run it through the visual studio debugger, it crashes and tells me "Unhandled exception at 0x68129759 in hyjkn.exe(a name i called a project i made to test it..): 0xC0000005: Access violation reading location 0x0000000c." and it only happens with bmp surfaces, because when i'v created one using SDL_CreateRGBSurface, it all worked fine... It happened also when i tried to use SDL_DisplayFormat, but i guess its because it uses SDL_ConvertSurface internally. anybody know what to do?
thanks

Re: SDL problem

Posted: Mon May 31, 2010 4:15 pm
by X Abstract X
Is your .bmp file in the right place?

Re: SDL problem

Posted: Mon May 31, 2010 4:18 pm
by Avishaiozeri
X Abstract X wrote:Is your .bmp file in the right place?
yes, its in the same directory. I made it write to me the SDL_GetError if the surface will be NULL (it wasn't loaded), and it didn't... it was loaded fine...
Edit:
If i write for example this, it happens:

Code: Select all

#include "SDL.h"

SDL_Surface *screen = NULL;

SDL_Event Event;
int main (int argc, char *argv[])
{
	SDL_Init(SDL_INIT_VIDEO);

	screen = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT);

	SDL_Surface *img = SDL_LoadBMP("a.bmp");
	SDL_Surface *ConvertedImg = SDL_ConvertSurface(img,screen->format,SDL_HWSURFACE);

	while (true)
	{
		if (SDL_PollEvent(&Event) == 0)
		{
		}else{
			if (Event.type == SDL_QUIT)
				break;
		}
	}
	
	return 0;
}

Re: SDL problem

Posted: Mon May 31, 2010 4:33 pm
by X Abstract X
I can't see a problem but do you realise that SDL_ConvertSurface returns the newly converted surface?

Re: SDL problem

Posted: Mon May 31, 2010 4:49 pm
by Avishaiozeri
Lol, i know, but thats not my program, i wrote it here to show you the problem, in my program the pointer is stored in an object of a player class...
Edit:
changed it, lol

Re: SDL problem

Posted: Mon May 31, 2010 4:56 pm
by X Abstract X
Oh I think maybe it's because your loading a 24 bit bmp then trying to convert it to a 32 bit format (likely your screen will get created at 32bpp).

Re: SDL problem

Posted: Mon May 31, 2010 4:59 pm
by Avishaiozeri
X Abstract X wrote:Oh I think maybe it's because your loading a 24 bit bmp then trying to convert it to a 32 bit format (likely your screen will get created at 32bpp).
It can't be done? How do i make a 32bpp bmp?
Edit: You're write, it is 24 bit. maybe i'll create a 24 bit screen...

Re: SDL problem

Posted: Mon May 31, 2010 5:03 pm
by X Abstract X
No, don't make the screen 24 bit. I'm not sure if it can be done or not, I don't use SDL. When you blit the surface onto the screen surface, they don't have to be the same format, do they?

Can't you just blit the 24 bit surface onto the 32 bit screen?

Re: SDL problem

Posted: Mon May 31, 2010 5:05 pm
by Avishaiozeri
I think they do, don't they? i mean, how can you add pixels from one format to a frame buffer of a different one?
Edit:
I tried making the screen 24 bit, but the error remains... maybe its VS? i mean, when i'm running it directly from the EXE and not from the debugger, it works.. maybe its a problem that doesn't do any harm...

Re: SDL problem

Posted: Mon May 31, 2010 5:07 pm
by X Abstract X
.

Re: SDL problem

Posted: Mon May 31, 2010 5:11 pm
by Avishaiozeri
X Abstract X wrote:check out SDL_DisplayFormatAlpha
Isn't it the same as SDL_DisplayFormat?
Edit: still happening... :x
I hate runtime errors about memory locations! how am i supposed to understand them??

Re: SDL problem

Posted: Mon May 31, 2010 5:15 pm
by X Abstract X
SDL_Surface *image = SDL_LoadBMP("pic.bmp");
SDL_Surface *goodImage = SDL_DisplayFormatAlpha(image);

Re: SDL problem

Posted: Mon May 31, 2010 5:16 pm
by Avishaiozeri
X Abstract X wrote:SDL_Surface *image = SDL_LoadBMP("pic.bmp");
SDL_Surface *goodImage = SDL_DisplayFormatAlpha(image);
Tried that...
i think all those functions use SDL_ConvertSurface internally...
Thanks for the help.
I think i just won't convert images... or i'll make a function that converts them myself, pixel by pixel...

Re: SDL problem

Posted: Mon May 31, 2010 5:17 pm
by X Abstract X
Heh I don't know then. I'm just spitting out whatever crap I can think of.

Re: SDL problem

Posted: Mon May 31, 2010 5:19 pm
by Avishaiozeri
X Abstract X wrote:Heh I don't know then. I'm just spitting out whatever crap I can think of.
lol, thanks for all your help
Me wrote:I think i just won't convert images... or i'll make a function that converts them myself, pixel by pixel...