Archived

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

DirectX 7 Confusing loop

This topic is 6077 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 am curently learning DirextX7 are saw this code in the SDK HRESULT hRet; while (TRUE) { hRet = g_pDDSBack->BltFast(0, 0, pdds, &rcRect, FALSE); if (hRet == DD_OK) break; if (hRet == DDERR_SURFACELOST) { hRet = RestoreAll(); if (hRet != DD_OK) break; } if (hRet != DDERR_WASSTILLDRAWING) break; } I understand that if the blt is succesful then you break out of the while loop. But if the surface was lost and the restore is succesful then if (hRet != DD_OK) break; will be false. Then if (hRet != DDERR_WASSTILLDRAWING) break; will be true and you will break out of the loop even though the surface was restored. The SDK said that if the restore was succesful it would loop back up to the blt statement. Did i understand this incorrectly? i would really appreciate some feedback.

Share this post


Link to post
Share on other sites
Lemme put it into words:

"Lets blit.

If the blit worked, we''re all done, so lets leave.

If it didn''t work, and the reason why is because we lost the surface, lets try to get it.

If we couldn''t get it restored, we break the loop, since trying to restore next time is futile. (Our intention to to report an error outside the loop.)

But if we could restore the surface, lets loop back to the top and try again.

If the original blit didn''t work, and it wasn''t because the surface was busy, we leave the while loop, since the only other errors are invalid parameters to BltFast, or a bad object. If the surface WAS still drawing, we can return to the top and see if it isn''y busy this time around."

And that would be the logic. The reason for the if(hRet != DD_OK) {break;} is because if it didn''t work, it won''t work next time, so theres so use in staying in the loop, so we leave and report an error.

Share this post


Link to post
Share on other sites
If the restore was succesful then it will go to the next statement which is if(hRet != DDERR_WASSTILLDRAWING) {break;}
This will be false so it will never get another chance to blit.
I think that it should be

else if(hRet != DDERR_WASSTILLDRAWING) {break;}

Does anyone else think this is correct. I guess the SDK may have made a typo.

Share this post


Link to post
Share on other sites
If it''s a typo, then it''s a big one, since that same kind of loop appears many different times in the SDK for different procedures. Therefore I think it''s purposely intended not to Blt if we recover the surface and just wait until the next execution loop.

Share this post


Link to post
Share on other sites