Archived

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

DDERR_SURFACELOSTand PeekMessage

This topic is 6034 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 trying to execute a simple DD program using C++. I have set up a primary surface in one class and have one sprite class that contains a DDS. The problem is, when the message loop uses GetMessage to process the messages, DD workes fine, but only animates when the GetMessage function falls through. When I change this to PeekMessage, I keep getting DDERR_SURFACELOST when I try to Blt. Performing a ->Restore and loading the image isn''t working on the sprite surface. Can anyone help?

Share this post


Link to post
Share on other sites
Even when using PeekMessage, you must still take the messages out of the message queue. So if you are leaving the messages in the queue when using PeekMessage you must do something like this:

while {GameRunning}
while (PeekMessage(&msg, hWnd, 0, 0, PM_NOREMOVE))
{
GetMessage(&msg,hWnd,0,0);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//Do drawing etc.
}

If you aren''t using the PM_NOREMOVE flag, then I''m not sure why it''s not working.

Share this post


Link to post
Share on other sites
Good technique, but I''m still getting the same error. What about a DD surace could PeekMessage affect that GetMessage won''t? I''ve never had a problem with a message loop before.

Share this post


Link to post
Share on other sites
PeekMessage shouldn''t do anything to affect a DDS... strange...

Does it happen every time you blt or only before/after/around a certain msg has been received?

btw, the following message loop gets rid of the GetMessage call (but works the same way):

  
while (game_running)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
game_running = false;
TranslateMessage(&msg);
DispatchMessage(&msg);
};
// Do drawing and other game-stuff here

};


Share this post


Link to post
Share on other sites