Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 2780 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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) {

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

//draw something

if(pSprite != NULL){ pSprite->End(); }
if(pD3DDevice != NULL){

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

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

Share this post

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

Share this post

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

Share this post

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

Share this post

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

Share this post

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

Share this post

Link to post
Share on other sites
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)
?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;
LPCSTR Name = "Window_Class_Name";
if (!hPreInst) {

[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=2]if (!RegisterClass(&myProg)) return FALSE;


[indent=1]hWnd = CreateWindow( (Name), (USERNAME), ... );



[indent=2]if( PeekMessage( &lpMsg, NULL, 0, 0, PM_REMOVE ) ){

[indent=3]if(lpMsg.message == WM_QUIT){ break; }

[indent=2]} else if ( Sys_LoopControl(60) ) {
[indent=3]FrameTime = (timeGetTime()-old_time)/F(1000);
old_time = timeGetTime();

Share this post

Link to post
Share on other sites
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;
?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), ... );
???if(lpMsg.message == WM_QUIT){ break; }
??} else if (Sys_LoopControl(60)){
???FrameTime = (timeGetTime()-old_time)/F(1000);
???old_time = timeGetTime();

Share this post

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

Share this post

Link to post
Share on other sites
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) {
?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

Share this post

Link to post
Share on other sites
Sign in to follow this  


Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!