• Advertisement

Archived

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

Wierd termination problem

This topic is 6555 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''ve just started a new game engine and have found the following odd problem in my initial testing... I have set up a simple WinMain and message handler and then have initialized DirectDraw7 and drawn some text on the screen to make sure everything is working. I then added a Flip() call: while (FAILED(primary->Flip(NULL, DDFLIP_WAIT))) {} This seems to work fine, but when I press Alt-F4 to exit, the window closes, but the program does not terminate. If I change the call to: if (FAILED(primary->Flip(NULL, DDFLIP_WAIT))) // print an error message... The programs still works and now it will terminate properly! I also tried a different approach to flipping: while (FAILED(primary->GetFlipStatus(DDGFS_ISFLIPDONE))) {} primary->Flip(NULL, DDFLIP_DONOTWAIT); which gave the same termination problem, but changing it to: if (!FAILED(primary->GetFlipStatus(DDGFS_ISFLIPDONE))) { primary->Flip(NULL, DDFLIP_DONOTWAIT); } Which works as it should. I can use the latter method, but i would prefer to have the GameMain() called only once each flip and not a bunch of extra times while its waiting... (I''m using DirectX7.0a on a Win2K system w/ MSVC++)

Share this post


Link to post
Share on other sites
Advertisement
this is how I handle closeing the app. it should work for you.

when you want to end the game from inside then calls
PostQuitMessage(0);

also in side you message pump put

if(msg.message==WM_QUIT)//this would be created by the X //button or by Alt-F4
PostQuitMessage(0);

then release all your objs then contiune to run JUST the msg pump. this way it gives windows a chance to end gracefully...

Great Milenko

Words Of Wisdom:
"Never Stick A Pretzel In Your Butt It Might Break Off In There."


http://www.crosswinds.net/~milenko
http://www.crosswinds.net/~pirotech

Share this post


Link to post
Share on other sites
Thanks, but that''s what I''m doing already I''m using a basic WinMain and WinProc that are slightly modified from LaMothe''s code examples.

The wierd thing is that is method works as long as I don''t use a while() loop is any way to control flipping, but fails if I do... I''m thinking this may have something to do with either DirectX7 and/or Windows2000 as this same approached worked in my first (very basic) tetris type game that I made with DirectX6 under Win98 (before I upgraded)

I can solve the problem by using one of the methods that do work, but I would really like to know what''s going on if anyone has any ideas since the while loops shouldn''t affect the windows message passing and translating in any way! Also, the while loop seems to be the standard way to do page flipping so it seems very odd that it is not working.

Thanks in advance for any ideas

Share this post


Link to post
Share on other sites
As I understand it, [ALT]+[F4] is does not quit a program, it simply closes the window. I have had this problem; the GUI shows that a program is running when it "isn''t". I had to select "Terminate Process" or [CTRL]+[ALT]+[DEL] and close it manually.

Anyway, the [ALT]+[F4] generates a WM_CLOSE (window) in the message loop, not WM_QUIT (app) So, in WinProc(), below WM_CLOSE you should PostQuitMessage(). I know you say that this isn''t the case, but in my experience, it has always been this. (I am not stubborn; nor trying to sound like a know-it-all)

And if this doesn''t solve your problem, perhaps another reader will encounter this someday, then remember these posts, and be enlightened.

Share this post


Link to post
Share on other sites
I guess I should clear things up a bit... My stripped down WinProc() handles WM_CLOSE by calling PostQuitMessage(0). Like I said, the program works fine as long as there is no while loop for flipping... that''s why I''m so confused about what''s going on Oh well, I guess I might have to put in some major debugging time at some point to try to track this one down, but for now I''ll make due with what works

(I really wish I knew what was going on, though!)

Share this post


Link to post
Share on other sites
I don''t do much work with fullscreen DX, but I think your window could be destroyed, then you try flipping and it keeps failing and failing...and it won''t let the app quit.

Instead, check for specific return values from Flip(), like this:

while( primary->Flip(NULL, DDFLIP_DONOTWAIT) == DDERR_WASSTILLDRAWING // DDERR_SURFACEBUSY ) {}
primary->Flip(NULL, DDFLIP_DONOTWAIT);

or perhaps something similar. The way you have it set up, it''ll keep trying regardless of any errors DX might encounter. You should never use the FAILED() macro except when debugging a particular function. FAILED() will return false on any error.

Good Luck!


- null_pointer

Share this post


Link to post
Share on other sites
quote:
Original post by chippydip

while (FAILED(primary->Flip(NULL, DDFLIP_WAIT))) {}




This seems wrong to me. You''re telling it to keep trying until it succeeds. Basically, if there is any critical error, your program is stuck in that loop forever. Perhaps hitting ALT-F4 creates such an error (can''t flip, cos the window is being closed). You shouldn''t need such a loop if you use the DDFLIP_WAIT flag, right? Cos pretty much any error except the already-busy one (sorry, I don''t have the DX docs here) is somewhat permanent.

Share this post


Link to post
Share on other sites
null_pointer: Thanks, I''ll bet that''s it! I''ll go check it now and post again if it doesn''t work... The while(FAILED(...)) seemed like the standard way to do a flip from code examples that I''ve seen, so I just figured it would work... now that I think about it, though, no wonder it hasn''t been terminating!

kylotan: Sounds like you are saying the same thing as null_pointer, I''ll check it out... it should work now!

Thanks for the help guys

Share this post


Link to post
Share on other sites

  • Advertisement