Jump to content
  • Advertisement
Sign in to follow this  
jdub

(C#) Why does a simple PeekMessage() lock up my computer

This topic is 3657 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 have this code:
Message msg;

            while (stillIdle)
            {
                //see if it is time to render
                if (gameTime.EllapsedTime >= (1000 / 60) || gameTime.IsFirstUpdate)
                {
                    Render3DEnviroment ( gameTime.EllapsedTime, gameTime.TotalTime );
                    UpdateGame ( gameTime.EllapsedTime, gameTime.TotalTime );
                }
            }
            while( PeekMessage(out msg, gameForm.Handle, 0, 0, 0) )
            {
                switch ((WM)msg.Msg)
                { 
                    case WM.MOUSEMOVE:
                        Application.Exit ();
                        break;
                }
            }

Every time I run it, the program freezes up. The window is cleared red as it should be but when I ran it in the debugger and set some breakpoints, it showed that the code was only hitting the while(PeekMessage(...)) loop. Why could this be? Could I be infinitely generating messages in this code? Thanks, jdub

Share this post


Link to post
Share on other sites
Advertisement
Where are you getting this PeekMessage function from? Is a P/Invoke to the native PeekMessage?

There's three obvious problems:

1. You're calling PeekMessage, but you're not doing anything with those messages (i.e. you're not calling TranslateMessage/DispatchMessage.)
2. You're passing 0 for the (presumably) wRemove parameter which means the message is not being removed from the queue -- you're just peeking the same message over and over.
3. You're passing in a window handle which means thread messages and messages for other windows will not be processed.

The solutions to these problems all stem from my first question: where did this PeekMessage function come from?

Share this post


Link to post
Share on other sites
It's also not clear what actually sets stillIdle to false. Are you sure you even get to the PeekMessage call? Although everything Codeka points out is true as well.

Share this post


Link to post
Share on other sites
dont know whats really the problem, but why dont you do it that way:


while(msg.message != WM_QUIT)
{

if(PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
{
// If there are Window messages then process them.
//translate/dispatch
}
else
{
// animate
}
}



works fine here

Share this post


Link to post
Share on other sites
Do you actually have a windows message proc setup? I think you still need one outside of peek message.

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!