Direct3D9 and multithreading

Started by
3 comments, last by Dookie 15 years, 1 month ago
Hello! I'm still new to multithreading, so forgive my ignorance if there's a painfully solution to my problem. [grin] First of all, I'm doing this to create my Direct3D object:
DXStuff->g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, DXStuff->hWnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED,
		&d3dpp, &DXStuff->g_pd3dDevice )
When I first start my game engine, I start an animated splashscreen for the player to see while game textures and sounds are loaded in the background. Here's how I load this splashscreen code:
_beginthread(SplashThread, 0, &sParams);
and here's the code for the above call:
void SplashThread(PVOID pvoid)
{
	PPARAMS pparams;

	pparams = (PPARAMS) pvoid;

	while (!pparams->threadDone)
	{
		UpdateGameTimer(pparams->DXStuff);
		RenderSplash(pparams->DXStuff, pparams->DXEnts);
	}

	CleanupSplash();

	_endthread();
}
When I'm done loading the game, I exit out of the SplashThread with "pparams->threadDone = true;" What's weird is that my game engine seems to be using an awful lot of CPU power than if I'm not using multithreading. Is it possible the SplashThread is still running in another thread even if I've ended it? Or, maybe it hasn't completely ended? Is there a way I can ensure ALL splash-related threads are completely closed when the game is completely loaded? Thanks in advance for the help!
"The crows seemed to be calling his name, thought Caw"
Advertisement
You can see all of your threads from the debugger
That sounds cool! How do I view the threads from the debugger? When I go to 'Debug' -> 'Windows' -> 'Threads', it brings up a 'Threads' panel in my IDE that is blank (I'm using Visual Studio 2002). That panel has columns labeled 'ID', 'Name', 'Location', 'Priority', 'Suspend', but there's nothing listed while my game engine's running. I compiled my game using the 'Debug' option, so I'm not sure why I can't see the threads.
"The crows seemed to be calling his name, thought Caw"
You run your engine with F5 or ctrl+F5? (not sure about your key bindings, but basically are you really debugging?)
Also you should probably break anywhere to be able to see the info easily, maybe put a breakpoint after your code has loaded and the thread is supposedly gone...
Oh, OK... I didn't know I had to break in order to see the threads. I see them now! Thanks for the info, I'm gonna do a little research to see why my game engine is such a CPU hog.
"The crows seemed to be calling his name, thought Caw"

This topic is closed to new replies.

Advertisement