Big WTF?(SDL)

Started by
3 comments, last by eedok 19 years, 2 months ago
well I finally brought my linux code to windows, and for some reason the thread code for the output doesn't work.. Here's the code:

int OutputThreadFunction(void * data)
{
	while(page!=close)
	{
		while(page==game)//Game screen
			GameOutput();	
	}
	
	return 0;
	
}

page is a global variable with type enum(close and game are 2 fields). Now here's where the WTF comes in, when I change my code to this, it works(except it greatly hinders performance when not on game page)!?

int OutputThreadFunction(void * data)
{
	while(page!=close)
	{
	    printf("");
	    while(page==game)//Game screen
		GameOutput();	
	}
	
	return 0;
	
}

Is there any explaination to why this would happen?
Advertisement
Hmmm, it indeed looks weird.... Ok, nothing more helpful to say at this moment, it simply depends on too many things (read: rest of your code).

I remember one time I had very strange problem when changing place of two const char * variables in function implementation changed behaviour of program. Reason? Of course, uninitialized pointers.
There was also situation when changing position of two normal ints in class definition changed behaviour of program... yeaah, pointers were overwriting some bits... :-/

Why I wrote that above? Just to show you that your printf stuff isn't that really weird and for sure there is stupid bug somewhere... maybe with pointers... maybe with threads... or maybe with sth absolutely unconnected with this function. Check it out once more, and if you want our (more specific) help, just post more code :-)
Try putting an SDL_Delay(1) in your while-loops.

int OutputThreadFunction(void * data){	while(page!=close)	{		while(page==game)//Game screen		{			SDL_Delay(1);			GameOutput();		}		SDL_Delay(1);	}	return 0;	}

Maybe your while-loops are eating all the cpu time and SDL doesn't get enough resources to draw anything.
baumep
int OutputThreadFunction(void * data){	printf(""); //try it here so it's not looped all the time, this should increase performance	while(page!=close)	{	    while(page==game)//Game screen		GameOutput();		}		return 0;	}
Quote:Original post by Anonymous Poster
*** Source Snippet Removed ***

This doesn't work
Quote:Original post by baumep
Try putting an SDL_Delay(1) in your while-loops.
*** Source Snippet Removed ***
Maybe your while-loops are eating all the cpu time and SDL doesn't get enough resources to draw anything.

IT WORKS!!! Rating++

This topic is closed to new replies.

Advertisement