C++ -- class bah(0) works, but...[FIXED]

Programming, for all ages and all languages.
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Post by Kevin McGuire »

I know some FPS games use thread, but not for a fact since I have never actually dived into the source and found out what those threads are doing. Anyhow they do use multiple threads (I have viewed the process using a process viewer on windows before). I imagine one is doing the actual calculations and the other is updating the screen... I dunno.

http://wiki.extremeoverclocking.com/wik ... aded_Games
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

I got one last idea that might work! Rather than havign the video update in an SDL thread, have the video update in the main() thread, and then have the actual robot stuff work in SDL thread, this also allows me greater thread control, like being able to pause the robot thread, where pausing the video update(/checking messages) thread, just shouldn't be done...

it will require a bit of recoding, but guess it's better than not using any threads..
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Post by Kevin McGuire »

I still wish I knew why it likes to crash when spawning another thread. Maybe like you said it stores some data that is relevant to the thread that initializes it. I will try that when I get a chance. Putting rendering code in the main thread..
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

-------FIXED-------

Finally, I fixed this stupid problem...
I did it by replacing

Code: Select all

int Thread_Messaging(void * arg){
	
	if( SDL_InitSubSystem(SDL_INIT_VIDEO) == -1 ){exit(1);}
	display.screen=SDL_SetVideoMode(640,480,8,SDL_HWSURFACE);
        display.vbuffer=new char[640*480*1+1]; /***THIS***/

    volatile unsigned int quit=0;
	while(quit==0){
		display.FlushBuffer();
		display.Render();
		if(SDL_PollEvent(&event)==1){
			switch(event.type){
				case SDL_QUIT:
				quit=1;
				quit_all=1;
				exit(0);
				break;
			}
		}else{
			SDL_Delay(50); //don't waste all the processing time..
		}
	}
	SDL_QuitSubSystem(SDL_INIT_VIDEO);
	quit_all=1;

	//SDL_QuitSubSystem(SDL_INIT_VIDEO);
	//while(quit_all==1){}

	//exit(0);
	//while(1){}
	return 0;

}
with

Code: Select all

int Thread_Messaging(void * arg){
	display.vbuffer=new char[640*480*1+1]; /**THE FIX!!!--INITIALIZE THIS _BEFORE_ SDL!! --this also fixed the exiting problem!**/
	if( SDL_InitSubSystem(SDL_INIT_VIDEO) == -1 ){exit(1);}
	display.screen=SDL_SetVideoMode(640,480,8,SDL_HWSURFACE);


    volatile unsigned int quit=0;
	while(quit==0){
		display.FlushBuffer();
		display.Render();
		if(SDL_PollEvent(&event)==1){
			switch(event.type){
				case SDL_QUIT:
				quit=1;
				quit_all=1;
				exit(0);
				break;
			}
		}else{
			SDL_Delay(50); //don't waste all the processing time..
		}
	}
	SDL_QuitSubSystem(SDL_INIT_VIDEO);
	quit_all=1;

	//SDL_QuitSubSystem(SDL_INIT_VIDEO);
	//while(quit_all==1){}

	//exit(0);
	//while(1){}
	return 0;

}
It really shouldn't matter since I use a 2second wait period, and vbuffer is volatile...but meh...SDL and threads aren't the best couple..
[/b]
Post Reply