Sign in to follow this  
Baltor

Passing a SDL_Screen Pointer...

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by Specchum
Also, SDL_Flip works like SDL_UpdateRects and not SDL_FillRects on systems that don't have double buffer.

Whoops. I stand corrected.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this