Passing a SDL_Screen Pointer...

Started by
9 comments, last by Gaiiden 19 years, 4 months ago
I have this code:

void InitTest(SDL_Surface* s)
{
 printf("\nList of Tests\n");
 printf("-------------\n");
	printf("1: Sound Test\n");
 printf("2: Map Test\n");
 printf("Please select test to run: ");
	int select;
	cin >> select;
	printf("\n");
	switch(select)
	{
	 case 1:
		 SoundManagerTest();
		 break;
	 case 2:
			MapManagerTest(s);
		 break;
		default:
			printf("Error. Invalid Entry\n");
			exit(1);
	}
}

void MapManagerTest(SDL_Surface* s)
{
	printf("Running MapManager test...\n");
	bool test;
 MapManager mapMan = MapManager(s, 600, 600);
	test = mapMan.AddMap("test", getDataFileLocation("Test.FMP"));
	test = mapMan.SetMap("test");
	printf("Test map name: test\n");
	printf("Test map height: %i\n", mapMan.MapHeight());
	printf("Test map height in blocks: %i\n", mapMan.MapHeightBlock());
	while (true)
	{
		printf("Drawing map...\n");
	 mapMan.DrawMap(0, 0);
	 SDL_Flip(s);
	 sleep(2);
		break;
	}
	while (true)
	{
	 printf("Drawing map at different location...\n");
	 mapMan.DrawMap(18, 27);
	 SDL_Flip(s);
	 sleep(2);
	}
	printf("Test complete\n");
}


When I call InitTest(screen), with screen being my pointer to the main SDL screen object (which works find), I get a Segmentation Fault. I know the problems lies in the call to SDLFlip(s) because if I remove then I get no error. I suspect a null pointer or something similar, but I cannot find the problem. If anyone could help me, I would greatly appreciate. Thanks.
Advertisement
Where's your main function?

And you're not trying to run this as a console app are you??

Drew Sikora
Executive Producer
GameDev.net

I didn't list my main function, but all it basically does right now is initiatilze my SDL stuff (which creates a windows and everything, that is working) and my test function. It has an SDL windows but also ouputs to the console for debugging perposes.
I should have specified that I was asking because there's nothing wrong with the code you posted. Lets see the DrawMap() function of your map manager

Drew Sikora
Executive Producer
GameDev.net

This is the DrawMap() function:
currentMap->MapUpdateAnims();currentMap->MapMoveTo(x, y);if (currentMap->MapChangeLayer(0) != -1) currentMap->MapDrawBGT(surface);else printf("Map has no layer 0, it cannot be drawn...\n");

It uses code from the SDLMappy library.
Still nothing. You say that you suspect it's a pointer problem when calling SDL_FLip. Have you tested this? If it is a bad pointer, just back track through your call stack or step through your app and keep track of the surface pointer.

Drew Sikora
Executive Producer
GameDev.net

Did you call SDL_SetVideoMode with SDL_DOUBLEBUF in the flags?

No offense meant ^^
---Just trying to be helpful.Sebastian Beschkehttp://randomz.heim.at/
Quote:Original post by randomZ
Did you call SDL_SetVideoMode with SDL_DOUBLEBUF in the flags?

That won't matter. If the surface isn't double buffered then SDL_Flip() will just call SDL_FillRect() instead of flipping the pages.

Drew Sikora
Executive Producer
GameDev.net

Why not put a breakpoint at the beginning of InitTest function and another one at where you do the SDLFlip and see if the pointers are pointing to the same surface? If they are then ur problem lies somewhere else.

Also, SDL_Flip works like SDL_UpdateRects and not SDL_FillRects on systems that don't have double buffer.
"There is no dark side of the moon." - Pink Floyd
Quote:Original post by Gaiiden
Quote:Original post by randomZ
Did you call SDL_SetVideoMode with SDL_DOUBLEBUF in the flags?

That won't matter. If the surface isn't double buffered then SDL_Flip() will just call SDL_FillRect() instead of flipping the pages.


I thought that was only the case if you specified SDL_DOUBLEBUF, but couldn't get it due to hardware reasons. But, thinking about it, it wouldn't make much sense to implement it that way ;)
---Just trying to be helpful.Sebastian Beschkehttp://randomz.heim.at/

This topic is closed to new replies.

Advertisement