Sign in to follow this  
eedok

Big WTF?(SDL)

Recommended Posts

eedok    982
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?

Share this post


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

Share this post


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

Share this post


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

}

Share this post


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

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