Dynamic sprite dirty flag (FIXED)

Started by Wretched, Tue 28/03/2006 09:28:12

Previous topic - Next topic

Wretched

Is there a way to tell an object its graphic has changed?
This code doesn't work as oReflection seems to think its graphic is not changing from frame to frame. I've got a work-around using two alternating dynamic sprites, but just thought I'd point it out as a possible bug.

in repeatedly_execute
Code: ags

if (DS!=null)
{
  DS.Delete();
}

ViewFrame *frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);

DS=DynamicSprite.CreateFromExistingSprite(frame.Graphic);
DS.Resize(DS.Width*player.Scaling/100, DS.Height*player.Scaling/100);
DS.Flip(eFlipUpsideDown);
oReflection.Graphic=DS.Graphic;


Edit by strazer: it's -> its

Edit by Wretched: Award for most pedantic edit ever -> strazer

Edit by Gilbert: Edited because he's amused that a moderator actually did this kind of edit. :=

Gilbert

I'm not quite sure, but I suspect that the DS.Delete() part might be related.

When you use Delete() the slot pointed to by DS.Graphic() will no longer exist, it may cause problem as the object oReflection is still using that slot. Try commenting out the DS.Delete() part and see if it makes any differences (possibly cause more troubles, I'm not sure := ).

SSH

As Gilbert says, you shouldn't really delete the sprite while the object still has it assigned
how about:

Code: ags

oReflection.Graphic=0;
if (DS!=null)
{
  DS.Delete();
}

ViewFrame *frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);

DS=DynamicSprite.CreateFromExistingSprite(frame.Graphic);
DS.Resize(DS.Width*player.Scaling/100, DS.Height*player.Scaling/100);
DS.Flip(eFlipUpsideDown);
oReflection.Graphic=DS.Graphic;

12

Gilbert

I think the Delete() may not be necesary (but yet need to be proven) as AGS claims to handle pointers wisely, that the content will be automagically released when no pointer is pointing to it (maybe when the object graphic is changed, the last instance of the DS is released).
However I think for safe-guard against warning message you should still delete DS when the room is left.

Wretched

Sorry, I forgot to mention this is in repeatedly_execute. As far as I can tell, objects make their own cached version of their current sprite. Since the Dynamic Sprite will keep getting assigned the same graphic value, the object doesn't know that the sprite is actually changing, as it only checks the graphic value. Hence the option for a dirty flag on dynamic sprite generated sprites. Should be internally controlled. Though, as I said, I can get around this by alternating dynamic sprites so that the graphic value changes each frame. And yes, I do delete the DynamicSprite on leaving the room.

Gilbert

Actually even though objects might have cached copies of sprites (not sure here) I doubt if it's really safe to Delete the DS there, as it should also render the sprite slot invalid, and oReflection.Graphic may still return that slot number.

Pumaman

#6
Quote from: Wretched on Tue 28/03/2006 13:33:16
As far as I can tell, objects make their own cached version of their current sprite. Since the Dynamic Sprite will keep getting assigned the same graphic value, the object doesn't know that the sprite is actually changing, as it only checks the graphic value.

Your theory is spot on. The cached copy of the object graphic automatically determines that it is stale if the sprite slot number changes, however in this case the slot number is being re-used but has a different graphic.

At the moment, DS.Delete() automatically removes it from any GUI buttons, so I'll do the same for objects.

Edit by strazer:
AGS v2.72 Beta 7:
* Deleting a dynamic sprite now flags any objects using it as dirty.

SMF spam blocked by CleanTalk