problem with simple d3d9 app

Started by
13 comments, last by pai 20 years, 2 months ago
hi there. i''ve just started to practice some dx9. after creating an dx object and getting the device to simply draw a blue screen (windowed) as described in the dx tutorials the window appearing always hangs my computer when another window is placed above the one i created. hanging means: mouse movement hangs, winamp hangs, and so on any idea what the problem is?
Advertisement
My guess would be something to do with either the message loop, or the handling of the WM_PAINT message (if you do indeed handle that). Moving a window around on top of yours causes Windows to send your application the WM_PAINT message, so maybe it''s in there that a problem occurs. It''s hard to tell, though. If it isn''t too large, could we see the WindowProc code and the message loop?
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
of course you can. :D
    while( WM_QUIT != msg.message  )    {                bGotMsg = ( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) != 0 );                if( bGotMsg )        {                        TranslateMessage( &msg );                        DispatchMessage( &msg );                } // if                else                {                        // Render einen Frame, wenn gerade keine andere Nachricht vorliegt.                        if( FAILED( Render3DEnvironment() ) )                                SendMessage( m_hWnd, WM_CLOSE, 0, 0 );                } // else        } // while

and the windowproc switch statement
    switch( uMsg )    {        case WM_PAINT:                                        Render3DEnvironment();                                        break;    case WM_DESTROY:                                        Cleanup3DEnvironment();                                        PostQuitMessage( 0 );                                        return 0;        default:                                        break;        } // switch
For proper WM_PAINT handling I think you need to call BeginPaint/EndPaint and return 0 after you handle it.

Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
Well, I don''t see anything definite, but...

1) BeginPaint()/EndPaint() might be important with typical GDI stuff, and it won''t hurt to try it, but if you''re using DX9 to draw, then I doubt it will be an issue.

2) I''ve heard of people having odd problems when their message loop handles only one message per iteration. Typically, it''s suggested to have a smaller loop that calls PeekMessage over and over until there is no message left (or a message was WM_QUIT), then do your game update/render stuff, and then repeat the outer loop.

I can''t see anything seriously wrong, though. Do you raise your thread/process priority anywhere? Because the most common cause of those symptons that I''ve had has been an infinite loop in a program with raised priority.

3) I just saw something. Maybe... Do you call DefWindowProc() in your WindowProc? Because that could cause some serious issues if you don''t. I noticed that your default: case was simply a break; , but I suppose you called DefWindowProc() after the switch statement most likely. But if not, that''ll change a lot of things.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
I believe if you don''t handle WM_PAINT, but do pass it on to DefWndProc it will do an empty pair of BeginPaint/EndPaint for you. You should definitely be calling DefWndProc for any message you do not handle yourself.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
hey everyone.

firstly: i found the problem but don''t really understand it atm. i just changed the message loop from the above quoted to the following code fragment:

MSG msg; while( GetMessage( &msg, NULL, 0, 0 ) ){  TranslateMessage( &msg );  DispatchMessage( &msg );} // while 


quote:Original post by Agony
2) I''ve heard of people having odd problems when their message loop handles only one message per iteration. Typically, it''s suggested to have a smaller loop that calls PeekMessage over and over until there is no message left (or a message was WM_QUIT), then do your game update/render stuff, and then repeat the outer loop.


i think i have to try your version, agony. what exactly is the difference between peekmessage and getmessage? and what version of the message loop would be better (if both were working correctly ;-)

thanks for your help.

-pai
ok. another thing is just found out: my window (peekmessage version) just hangs when its completely disguised. if there is just a part of the window disguised nothing hangs.

any idea?
Try to run your program under spy++ to see if there is something wrong.

I don't understand how your second version of message loop can draw anything, you don't call your rendering function.

From msdn :
"Unlike GetMessage, the PeekMessage function does not wait for a message to be posted before returning."

Are you using thread ?


[edited by - arsouille on February 6, 2004 6:34:40 PM]
quote:Original post by Arsouille
Try to run your program under spy++ to see if there is something wrong.

I don't understand how your second version of message loop can draw anything, you don't call your rendering function.

From msdn :
"Unlike GetMessage, the PeekMessage function does not wait for a message to be posted before returning."

Are you using thread ?

hey arsouille, you're right. the call to the rendering function has been in the 'catch WM_PAINT' statement.

as i don't know what you mean by thread, i suppose i don't use it ;-)

[edited by - pai on February 6, 2004 6:52:36 PM]

This topic is closed to new replies.

Advertisement