SDL Surfaces

Hey!
I am new to SDL library and I have problem. I am trying to fill surface called ground and then blit it to main screen surface. When I am debugging my code, I my window crashes and this appear
1
2
First-chance exception at 0x00051537 in testpowierzchnie.exe: 0xC0000005: Access violation reading location 0x00000004.
Unhandled exception at 0x00051537 in testpowierzchnie.exe: 0xC0000005: Access violation reading location 0x00000004.

Here is something wrong with filling ground surface, if I remove it, everything works.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <SDL.h>

using namespace std;

SDL_Surface * ground=NULL;
SDL_Surface * screen=NULL;
SDL_Event event;

int main(int argc, char * args[])
{
	SDL_Init(SDL_INIT_EVERYTHING);
	screen=SDL_SetVideoMode(1080,768,32,SDL_SWSURFACE);
	SDL_FillRect(ground,NULL,SDL_MapRGB(ground->format,22,222,192));
	SDL_BlitSurface(ground,NULL,screen,NULL);

	while(1)
	{
		if(SDL_PollEvent(&event))
		{
			if(event.type==SDL_QUIT)
				break;
		}
		SDL_Flip(screen);
	}


	SDL_FreeSurface(screen);
	SDL_FreeSurface(ground);
	SDL_Quit();
	return 0;
}
Adamoll wrote:
blit
Which version of SDL are you using?

Also, I'm not too familiar with SDL, but some of that code looks suspicious, to say the least - ground and screen are both null yet you pass them as parameters as if they are initialized.
Last edited on
Did you try turning your computer off and on?

lol
I am using version 1.2.15 and something is wrong with code not with my computer.
ground is still NULL on line 14.
Thanks maeriden, it was necessary to add at the beginning
 
ground=SDL_CreateRGBSurface(SDL_SWSURFACE,1080,768,32,0,0,0,0);

Problem solved :)
Last edited on
Topic archived. No new replies allowed.