Advertisement Jump to content
Sign in to follow this  
luasitdown

initialize

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

MSG msg; while(msg.message !=WM_QUIT) { .... if msg is not been initalized? why runtime error arise?? I just do a compare operation.

Share this post


Link to post
Share on other sites
Advertisement
if your msg is not been initialized there is also no data attached to your msg var. The compiler can't do the comparision and the run-time error arises.

(It would be easier for us if we know which error arises.)

Share this post


Link to post
Share on other sites
If that's the entire example then the problem is that you've never actually set the message to anything (through GetMessage or PeekMessage for example).
The loop will likely have to be restructured such that the message retrieval function is called first. Try calling it within the while expression, switch to a do { .. } while() loop or an internal if condition that breaks out of it.

Share this post


Link to post
Share on other sites
Nah, you just need to put
ZeroMemory(&msg, sizeof(MSG));
right after you declare msg, otherwise it'll just be filled with garbage.

So it should look like this:
	MSG msg;
ZeroMemory(&msg, sizeof(MSG));
while (msg.message != WM_QUIT) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg); }
//myDx->render();
}



EDIT: oops, commented out mushu-specific code [lol]

Share this post


Link to post
Share on other sites
Quote:
Original post by Mushu
Nah, you just need to put
ZeroMemory(&msg, sizeof(MSG));
right after you declare msg, otherwise it'll just be filled with garbage.
I guess that works but you probably only replaced a gamble at runtime for one at compiletime.
What if WM_QUIT happened to be defined as 0 (it's 18 by the way)? I suppose that the loop is unlikely to have any significant extra processing of WM_NULL but this kind of assumption still seems is a bit dangerous to me.

Besides replacing the loop with a 'do { } while' would simplify the code without affecting it's behaviour.

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.

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!