SDL problem

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Avishaiozeri
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Wed Mar 17, 2010 4:32 pm

SDL problem

Post 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
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: SDL problem

Post by X Abstract X »

Is your .bmp file in the right place?
Avishaiozeri
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Wed Mar 17, 2010 4:32 pm

Re: SDL problem

Post 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;
}
Last edited by Avishaiozeri on Mon May 31, 2010 4:51 pm, edited 1 time in total.
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: SDL problem

Post by X Abstract X »

I can't see a problem but do you realise that SDL_ConvertSurface returns the newly converted surface?
Avishaiozeri
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Wed Mar 17, 2010 4:32 pm

Re: SDL problem

Post 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
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: SDL problem

Post 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).
Avishaiozeri
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Wed Mar 17, 2010 4:32 pm

Re: SDL problem

Post 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...
Last edited by Avishaiozeri on Tue Jun 01, 2010 4:12 pm, edited 1 time in total.
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: SDL problem

Post 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?
Avishaiozeri
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Wed Mar 17, 2010 4:32 pm

Re: SDL problem

Post 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...
Last edited by Avishaiozeri on Mon May 31, 2010 5:10 pm, edited 2 times in total.
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: SDL problem

Post by X Abstract X »

.
Last edited by X Abstract X on Mon May 31, 2010 5:16 pm, edited 1 time in total.
Avishaiozeri
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Wed Mar 17, 2010 4:32 pm

Re: SDL problem

Post 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??
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: SDL problem

Post by X Abstract X »

SDL_Surface *image = SDL_LoadBMP("pic.bmp");
SDL_Surface *goodImage = SDL_DisplayFormatAlpha(image);
Avishaiozeri
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Wed Mar 17, 2010 4:32 pm

Re: SDL problem

Post 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...
Last edited by Avishaiozeri on Mon May 31, 2010 5:18 pm, edited 1 time in total.
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: SDL problem

Post by X Abstract X »

Heh I don't know then. I'm just spitting out whatever crap I can think of.
Avishaiozeri
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Wed Mar 17, 2010 4:32 pm

Re: SDL problem

Post 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...
Post Reply