Sign in to follow this  
adamggg

bltfast error: DDERR_INVALIDRECT

Recommended Posts

adamggg    122
I'm running a fullscreen app with directdraw in C++. I have a function for loading maps that clears the current map and then draws all the objects for the selected map. Sometimes when a new map is loaded, 1 sprite is not drawn. As far as I can tell, it is always 1 sprite. Once this problem appears, reloading the map over and over will cause different sprites to disappear. But always 1 sprite. I'm using BltFast to draw sprites:
lpBackBuffer->BltFast(X,Y, &r, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);
I checked the errors when this problem occurs, and it is DDERR_INVALIDRECT. So I apparently have either an invalid source or destination rectangle. This is strange because there is no change in source & destination rectangles when the object is drawn correctly. I suppose this error points to a clipper issue since you can't use a clipper with BltFast, but my maps do not scroll so everything is contained within the boundaries of the screen. Pressing Alt+Tab to minimize the app and then coming back in will cause the missing object to reappear. But all I do in my restore function is reload the sprite:
sprite=DDLoadBitmap(pDD,"sprite.BMP",0,0);
DDSetColorKey(sprite, RGB(0, 0,64));
This would seem to imply that the sprite was not previously loaded correctly. If such was the case, would DDERR_INVALIDRECT be the error that shows up? I suppose I can get around the problem by reloading the bitmap whenever a DDERR_INVALIDRECT error shows up, but I would like to determine the root cause. Thanks

Share this post


Link to post
Share on other sites
Aardvajk    13205
Strange. I can only assume, if Alt-tabbing in and out brings it back, that the surface is becoming "lost" somehow, although in my experience that only happens when you tab out of a full screen DirectDraw app and Windows overwrites memory with something else.

I remember the documentation used to say the lost surfaces could occur "for a number of reasons". Most of the DirectDraw samples I've seen seem to be constantly checking for lost surfaces and reloading them when required so perhaps that is not such a bad solution.

I never wrote code that did that, though, and never experienced the problem you are describing.

[EDIT] Thinking about it though, if that were the case, BltFast should be returning DDERR_SURFACELOST, not DDERR_INVALIDRECT so ignore me. All I can suggest is you post some code.

[Edited by - EasilyConfused on August 17, 2006 10:38:56 AM]

Share this post


Link to post
Share on other sites
adamggg    122
Thank you for your reply. I'll post what should be the relevant code.

This is an excerpt from my Load Map function that loads a Tree object from tree.bmp:



else if(choice==TREE){
tree[count]=DDLoadBitmap(pDD,"tree.BMP",0,0);

top_frame[TREE][0]=1;
bot_frame[TREE][0]=40;
left_frame[TREE][0]=1;
right_frame[TREE][0]=40;
DDSetColorKey(tree[count], RGB(0, 0, 64));
curr_frame[TREE][count]=0;

}



And this is an excerpt from the Draw function that draws each tree object. The count increment section does have 2 plus signs but they don't show up in my preview for some reason:

for(count=0; count<max_instant[TREE]; count++){
r.left = left_frame[TREE][curr_frame[TREE][count]];
r.top = top_frame[TREE][curr_frame[TREE][count]];
r.right = right_frame[TREE][curr_frame[TREE][count]];
r.bottom = bot_frame[TREE][curr_frame[TREE][count]];


lpBackBuffer->BltFast(unsigned long(position_x[TREE][count])-bit_offset,
unsigned long(position_y[TREE][count])-bit_offset,tree[count], &r,
DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);




Maybe I should cast position_x[][]-bit_offset as an unsigned long instead of casting position_x[][] as an unsigned long and then subtracting bit_offset. position_x[][] is a float and bit_offset is an int. I never really paid attention to it before, but is my casting method poor here?

Also, it is inefficient to declare top_frame, bot_frame, etc for each Tree object, but that shouldn't be a problem.

If curr_frame[TREE][count] was something other than 0, an Invalid Rectangle would make sense. I am almost positive that this is not what happened, but I will make sure to verify.

Thanks

Share this post


Link to post
Share on other sites
adamggg    122
The sprites that I need in every level (like the player's character, a door, etc) are loaded when the game initializes, and all the other sprites are loaded as needed when a new map is loaded. It appears that only the level specific sprites are disappearing. The BltFast function is called at the same general location on both types of sprites, so maybe the DDLoadBitmap function is returning an error for the level specific sprites. I tried to test for the object being equal to NULL after calling DDLoadBitmap, but I didn't get any hits. Is there a list of error codes for DDLoadBitmap? I searched but had trouble finding any error checks except checking for NULL.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this