Community

SCI Programming => SCI Syntax Help => Topic started by: MusicallyInspired on April 04, 2016, 04:51:57 PM

Title: Check if an object is disposed?
Post by: MusicallyInspired on April 04, 2016, 04:51:57 PM
I have several Actors in a sequence one by one moving to the same destination on the horizon and when they reach that point they are disposed. I already have code to handle this and it works great. However, Before the last few Actors reach the destination the scene changes and at that point I want the code to dispose of objects that aren't already disposed yet. Is there a way to check if an object is already disposed and if it isn't dispose it?

Right now I just have the code that disposes each Actor as it reaches its destination and I also have another block of code that just disposes all of them (whether they are disposed or not) when the scene changes. This works, but I guess I'd just like a more elegant way to code this so that I'm not repeating actions.
Title: Re: Check if an object is disposed?
Post by: lskovlun on April 04, 2016, 05:32:23 PM
Right now I just have the code that disposes each Actor as it reaches its destination and I also have another block of code that just disposes all of them (whether they are disposed or not) when the scene changes. This works, but I guess I'd just like a more elegant way to code this so that I'm not repeating actions.
Either set the property/variable you get the pointer from to zero once disposed (checking for zeroes later) or use the IsObject call. Also, this is going to be fragile. The bug mentioned at http://www.sierrahelp.com/forums/viewtopic.php?f=9&t=1511 (http://www.sierrahelp.com/forums/viewtopic.php?f=9&t=1511) is due to a double free, and happened in an official game (we patched around it in ScummVM).
Title: Re: Check if an object is disposed?
Post by: troflip on April 04, 2016, 06:00:16 PM
I also have another block of code that just disposes all of them (whether they are disposed or not) when the scene changes.

Why? Anything in the cast list will be disposed when the room changes. I guess I'm not understanding what problem you're trying to solve?
Title: Re: Check if an object is disposed?
Post by: Kawa on April 04, 2016, 06:16:45 PM
Why not hide them when they reach the target instead of disposing of them? It's safer and it looks the same to the player. Besides what troflip just said.
Title: Re: Check if an object is disposed?
Post by: MusicallyInspired on April 04, 2016, 07:11:47 PM
I also have another block of code that just disposes all of them (whether they are disposed or not) when the scene changes.

Why? Anything in the cast list will be disposed when the room changes. I guess I'm not understanding what problem you're trying to solve?

The scene changes, but the room doesn't change. Everything is happening in the same script. It merely draws and transitions to a new picture.

Why not hide them when they reach the target instead of disposing of them? It's safer and it looks the same to the player. Besides what troflip just said.

That's a good idea. Thanks!

Either set the property/variable you get the pointer from to zero once disposed (checking for zeroes later) or use the IsObject call. Also, this is going to be fragile. The bug mentioned at http://www.sierrahelp.com/forums/viewtopic.php?f=9&t=1511 (http://www.sierrahelp.com/forums/viewtopic.php?f=9&t=1511) is due to a double free, and happened in an official game (we patched around it in ScummVM).

I'm fairly certain nothing would happen as everything is locked to a pretty cycle-specific sequence where no user input it possible (unless it is skipped entirely), but even so the above suggestion by Kawa would probably be a safer bet.
Title: Re: Check if an object is disposed?
Post by: troflip on April 04, 2016, 07:58:03 PM
Yeah, kawa's suggestion seems like the most straightforward thing to do.

Alternatively, you could change your script to use different rooms (and maybe use a region or other scripts for for common logic). Don't know if that would work for you.

If you're doing something like calling DrawPic directly to change "the scene", keep in mind this won't survive a save game/restore game (i.e. saving the game after the scene change, and then restoring it - it will still show the old background). I think this would probably be addressed by using the drawPic method on the current room instead.

Anyway, doing a "scene change" without a room change seems like a bit of a code smell to me, so be sure to check things work properly for save games.
Title: Re: Check if an object is disposed?
Post by: Kawa on April 04, 2016, 08:24:08 PM
I do this in my game's intro which, being a cutscene, avoids the save/restore issue.
Title: Re: Check if an object is disposed?
Post by: troflip on April 04, 2016, 08:29:24 PM
Yeah, makes sense for cutscenes.
Title: Re: Check if an object is disposed?
Post by: MusicallyInspired on April 04, 2016, 08:39:33 PM
This is an introduction sequence.
Title: Re: Check if an object is disposed?
Post by: Kawa on April 05, 2016, 03:36:29 AM
No issues then :3
Title: Re: Check if an object is disposed?
Post by: Cloudee1 on April 13, 2016, 09:37:15 PM
Why not hide them when they reach the target instead of disposing of them? It's safer and it looks the same to the player. Besides what troflip just said.
Might I also suggest positioning them off screen (400 400 seems to be my go to position for this) at the same time that you hide them. If you are going to be moving other things around the screen following the part where you hide these views then they may actually get hung up on them and it will take you longer than it should to figure out why.  :P