• Advertisement

Archived

This topic is now archived and is closed to further replies.

problem with simple d3d9 app

This topic is 5095 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

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?

Share this post


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

Share this post


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


Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
sorry.. for that post

[edited by - pai on February 6, 2004 6:51:14 PM]

Share this post


Link to post
Share on other sites
for that one too.. pressed wrong button

[edited by - pai on February 6, 2004 6:51:34 PM]

Share this post


Link to post
Share on other sites
PeekMessage will return immediately, whether there was a message or not. If there was, then it returns true, and the message structure is filled in (and removed if you specify PM_REMOVE). If there was no message, then it returns false, and it doesn''t matter what''s in the message structure.

GetMessage does not always return immediately. If there is at least one message, it fills in the message structure and returns. If there are no messages at the moment, it will just wait from within GetMessage until a message occurs, and then fill in the message structure and return.

For game development, PeekMessage is usually what is wanted, because we usually need to do stuff every frame, whether there is a message or not, such as rendering, physics, etc.

A suggestion, now that I think about it... Put a Sleep(0) right at the end of (but inside) your main while loop. That''ll tell Windows that other programs can do other stuff if they need to, but that you want control back again as soon as possible.

As for asking what threads are, they allow multiple streams of execution to occur at once. Just as you have multiple programs running on your computer at once, with Windows determining when each one can get control of the processor, you can also get multiple threads to run inside your program alone, and Windows (or any other OS) will manage how much CPU time is allotted to each. For example, you could have a rendering thread, that just loops around and around rendering, while another thread runs and handles input and the physics engine. In effect they''ll be running at the same time. But you needn''t worry about that right now.

Share this post


Link to post
Share on other sites
quote:
Original post by Agony
A suggestion, now that I think about it... Put a Sleep(0) right at the end of (but inside) your main while loop. That''ll tell Windows that other programs can do other stuff if they need to, but that you want control back again as soon as possible.

As far as I recall, the default minimum timer resolution is 10 ms. That means a Sleep(0) will sleep for at least 10 ms. So if you want to use Sleep, make sure you call timeBeginPeriod(1) to set the resolution to 1ms.


Muhammad Haggag

Share this post


Link to post
Share on other sites
Timer resolution shouldn''t affect how Sleep() works. And I tested it, just to make sure. Indeed, Sleep(0) on average seemed to sleep for 0.002 milliseconds (I didn''t have any other major programs running), while Sleep(10) slept for just about exactly 10 milliseconds. This was with timeBeginPeriod(10) called before anything else. Here''s the test code (which needs to be linked with winmm.lib for timeBeginPeriod to work):


#include <windows.h>
#include <cstdio>

int main()
{
LARGE_INTEGER Frequency;
LARGE_INTEGER StartTime;
LARGE_INTEGER CurrentTime;

int i;

timeBeginPeriod(10);

QueryPerformanceFrequency(&Frequency);

for (i = 0; i < 8; ++i)
{
QueryPerformanceCounter(&StartTime);
Sleep(0);
QueryPerformanceCounter(&CurrentTime);
printf("%14.12f\n", (double)(CurrentTime.QuadPart - StartTime.QuadPart) / (double)(Frequency.QuadPart) * 1000.0);
}

for (i = 0; i < 8; ++i)
{
QueryPerformanceCounter(&StartTime);
Sleep(10);
QueryPerformanceCounter(&CurrentTime);
printf("%14.12f\n", (double)(CurrentTime.QuadPart - StartTime.QuadPart) / (double)(Frequency.QuadPart) * 1000.0);
}

return 0;
}

Share this post


Link to post
Share on other sites

  • Advertisement