Jump to content

  • Log In with Google      Sign In   
  • Create Account


[directX] as the screen went frozen at D3DDevice->Present and leaves no error message


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 hiro4476   Members   -  Reputation: 122

Like
0Likes
Like

Posted 24 February 2012 - 01:41 PM

I'm at my limit...
This game uses the Library which is provided by my school.
The same code works fine in my school's computer but not in my notebook.
I've been debuging this days after days (although not continuously)

The HRESULT returned from CreateDevice has no problem as far as I can see. (the result was 0 I think)
with the D3DCREATE_HARDWARE_VERTEXPROCESSING setting, the last trace is "pD3DDevice->Present.s"
and the screen went frozen, leaves no error messages.
with the D3DCREATE_SOFTWARE_VERTEXPROCESSING setting, it's extreamly slow. but won't freeze (maybe too slow to even not get to the point yet)
since it has no error messages and it's un-debug-able...
I've been googling for days, and still have no idea what's going on.

can anyone give me a direction, where should I start looking?

pSprite is a LPD3DXSPRITE
And this is the snippet in the gameLoop

while( LOOP ) {
	 if(pD3DDevice != NULL) {
		  pD3DDevice->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f,0);
	 }

	 if(pD3DDevice != NULL) { pD3DDevice->BeginScene(); }
	 if(pSprite != NULL) { pSprite->Begin(D3DXSPRITE_ALPHABLEND); }

	 //draw something

	 if(pSprite != NULL){ pSprite->End(); }
	 if(pD3DDevice != NULL){
		  hc::trace("pD3DDevice->EndScene.s");
		  pD3DDevice->EndScene();
		  hc::trace("pD3DDevice->EndScene.e");
	 }

	 HRESULT hr;
	 if( pD3DDevice != NULL ) {
		  hc::trace("pD3DDevice : %d", pD3DDevice);
		  hc::trace("pD3DDevice->Present.s");
		  hr = pD3DDevice->Present(NULL,NULL,NULL,NULL);
		  hc::trace("pD3DDevice->Present.e");
	 }
}


Actually, before this happened, I had "LNK1000: Internal error during IncrBuildImage" error at every compile.
the hotfix VS90-KB948127 fixed it but still....
it could be the problem of my graphic card...
my graphic card is ATI Mobility Radeon X2300. a VAIO notebook probably 2 years old.

But then if I can create something like this with no problem in compiling and executing http://hiro4476.blog...about-demo.html
it could also be something wrong within the school's Library?


Regards, Hiro

Sponsor:

#2 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 25 February 2012 - 10:25 AM

You mean your program froze, or system (computer) froze?

If it's computer then I had similar problem myself. It was driver issue. Driver wasn't checking whether all parameters are set and caused silent crash. Make sure you set primitive topology, shaders and other stuff.

#3 Tom KQT   Members   -  Reputation: 1557

Like
0Likes
Like

Posted 25 February 2012 - 11:11 AM

Try to enable the DX debug runtimes (http://legalizeadulthood.wordpress.com/2009/06/28/direct3d-programming-tip-5-use-the-debug-runtime/) and watch for any errors or warnings in the output window of Visual Studio.

#4 hiro4476   Members   -  Reputation: 122

Like
0Likes
Like

Posted 28 February 2012 - 08:57 AM

Thanks to Tom's tip, I've managed to fix it!!
I fix it by providing a D3DCREATE_MULTITHREADED tag to the CreateDevice().


I also received a huge amount of
Direct3D9: (WARN) :Ignoring redundant SetSamplerState Sampler: 0, State: xx
Direct3D9: (WARN) :Ignoring redundant SetRenderState xx
even I comment'em.
guess there are ok I think.

and thanks to Ripiz too. but the froze was a program froze.
I've also googled the primitive topology, it seems like it's a DX10 feature?
Is there a equivalent feature/setting for the DX9? might as double check it.

#5 hiro4476   Members   -  Reputation: 122

Like
0Likes
Like

Posted 28 February 2012 - 09:42 AM

btw, here's the Warning message,

Device that was created without D3DCREATE_MULTITHREADED is being used by a thread other than the creation thread.
The thread Win32 Thread has exited with code 0 (0x0).

and also, is there a way to check if a D3DCREATE_MULTITHREADED is needed? like if I bring this game back to my school.

#6 Evil Steve   Members   -  Reputation: 1959

Like
0Likes
Like

Posted 29 February 2012 - 11:47 AM

D3DCREATE_MULTITHREADED is needed if the D3D device is used from more than one thread. Using the device from multiple threads is an extremely bad idea in D3D9, it has a fairly major performance penalty associated with it. If it's just for some test code then it's probably fine to use, but a "proper" game should never be using D3D from multiple threads.

If the library is provided by your school, then it must be creating the device from a different thread than your "main" thread.

Steve Macpherson
Senior programmer, Firebrand Games


#7 hiro4476   Members   -  Reputation: 122

Like
0Likes
Like

Posted 29 February 2012 - 06:42 PM

thanks for the tips. but I'm not sure about this "main" thread thingy.
And I don't think it's related to http://stackoverflow.com/questions/266168/simple-example-of-threading-in-c

I've try moving CreateDevice and every related codes into WinMain but it's not getting any better though...
it was all in other cpp called Gp3Lib.cpp.

the original WinMain look like this
int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hPreInst,LPSTR lpszCmdLine,int nCmdShow)
{
 stageInfo::readinFileTable();
 Sys_SetScreenMode();
 return DoWindow(hInstance,hPreInst,lpszCmdLine,nCmdShow);
}


the only thing I can suspect the odd is the "while(true){" loop at the DoWindow call
BOOL DoWindow(HINSTANCE hInstance, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow) {
[indent=1]MSG pMsg;
WNDCLASS myProg;
LPCSTR Name = "Window_Class_Name";
if (!hPreInst) {[/indent]
[indent=2]myProg.style = CS_HREDRAW | CS_VREDRAW;
myProg.lpfnWndProc = WndProc;
myProg.cbClsExtra = 0;
myProg.cbWndExtra = 0;
myProg.hInstance = hInstance;
myProg.hIcon = LoadIcon(hInstance,"MAIN");
myProg.hCursor = LoadCursor(NULL, IDC_ARROW);
myProg.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
myProg.lpszMenuName = NULL;
myProg.lpszClassName = (Name);[/indent]
[indent=2]if (!RegisterClass(&myProg)) return FALSE;[/indent]
[indent=1]}[/indent]
[indent=1]hWnd = CreateWindow( (Name), (USERNAME), ... );[/indent]
[indent=1]InitDxLib();
OnCreate();
Sys_CreateLoadThread();
InitPlayerInput();
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);[/indent]

[indent=1]while(true){[/indent]
[indent=2]if( PeekMessage( &lpMsg, NULL, 0, 0, PM_REMOVE ) ){[/indent]
[indent=3]if(lpMsg.message == WM_QUIT){ break; }
TranslateMessage(&lpMsg);
DispatchMessage(&lpMsg);[/indent]
[indent=2]} else if ( Sys_LoopControl(60) ) {[/indent]
[indent=3]FrameTime = (timeGetTime()-old_time)/F(1000);
old_time = timeGetTime();
GameLoop();[/indent]
[indent=2]}[/indent]
[indent=2]Sleep(1);[/indent]
[indent=1]}
OnDestroy();
DelDxLib();
_CrtDumpMemoryLeaks();
return((int)lpMsg.wParam);[/indent]
}


#8 hiro4476   Members   -  Reputation: 122

Like
0Likes
Like

Posted 29 February 2012 - 06:45 PM

omg, that was a bad indentation!! and it look like I can not re-edit or preview before I post...
BOOL DoWindow(HINSTANCE hInstance, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow) {
 MSG pMsg;
 WNDCLASS myProg;
 LPCSTR Name = "Window_Class_Name";
 if (!hPreInst) {
  myProg.style = CS_HREDRAW | CS_VREDRAW;
  myProg.lpfnWndProc = WndProc;
  myProg.cbClsExtra = 0;
  myProg.cbWndExtra = 0;
  myProg.hInstance = hInstance;
  myProg.hIcon = LoadIcon(hInstance,"MAIN");
  myProg.hCursor = LoadCursor(NULL, IDC_ARROW);
  myProg.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  myProg.lpszMenuName = NULL;
  myProg.lpszClassName = (Name);
  if (!RegisterClass(&myProg)) return FALSE;
 }
 hWnd=CreateWindow( (Name), (USERNAME), ... );
 InitDxLib();
 OnCreate();
 Sys_CreateLoadThread();
 InitPlayerInput();
 ShowWindow(hWnd,nCmdShow);
 UpdateWindow(hWnd);
 while(true){
  if(PeekMessage(&lpMsg,NULL,0,0,PM_REMOVE)){
   if(lpMsg.message == WM_QUIT){ break; }
   TranslateMessage(&lpMsg);
   DispatchMessage(&lpMsg);
  } else if (Sys_LoopControl(60)){
   FrameTime = (timeGetTime()-old_time)/F(1000);
   old_time = timeGetTime();
   GameLoop();
  }
  Sleep(1);
 }
 OnDestroy();
 DelDxLib();
 _CrtDumpMemoryLeaks();
 return((int)lpMsg.wParam);
}


#9 Adam_42   Crossbones+   -  Reputation: 2450

Like
0Likes
Like

Posted 29 February 2012 - 07:32 PM

I'm guessing that "Sys_CreateLoadThread();" involves creating a thread to load resources. Loading resources requires the D3D device at some point.

By the way to get rid of the annoying redundant render state messages, change the debug output level to one step below the maximum.

#10 hiro4476   Members   -  Reputation: 122

Like
0Likes
Like

Posted 03 March 2012 - 02:02 PM

Tahnks Adam!
you are genius!
how could I have missed that XD


although this is barely scrashing the directX.

void Sys_CreateLoadThread() {
 HANDLE newThread;
 InterlockedExchange((volatile LONG*)&_LoadEnd,0);
 newThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Sys_LoadThread,hWnd,0,NULL);
}

void Sys_LoadThread(HWND hWnd) {
 OnLoading();
 InterlockedExchange((volatile LONG*)&_LoadEnd,1);
}

and inside the OnLoading(), it's just for loops to load all the resources specified...
_LoadEnd is not been used anywhere but insides the above 2 functions.
as googled... think the WaitForSingleObject is needed but it's not been used.
I'm a lilo confused here...
so it created a new thread to load resource.
but not waiting for the loading to complete...

if that assumption is true, then probably it explains why the program yells LOADING FAIL occasionally.


ahyhow, I've restored everything back to what it was, but replaced Sys_CreateLoadThread() with the OnLoading()
so far, and I think it is sweet.


I DO think this API needs a rewrite...
besides this, I've caught quit some bugs too...


Kindly Regards to oeveryone, Hiro




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS