Author Topic: Check if an object is disposed?  (Read 8060 times)

0 Members and 1 Guest are viewing this topic.

Offline MusicallyInspired

Check if an object is disposed?
« 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.
« Last Edit: April 04, 2016, 04:54:18 PM by MusicallyInspired »


Brass Lantern Prop Competition

Offline lskovlun

Re: Check if an object is disposed?
« Reply #1 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 is due to a double free, and happened in an official game (we patched around it in ScummVM).

Offline troflip

Re: Check if an object is disposed?
« Reply #2 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?
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Kawa

Re: Check if an object is disposed?
« Reply #3 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.

Offline MusicallyInspired

Re: Check if an object is disposed?
« Reply #4 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 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.
Brass Lantern Prop Competition

Offline troflip

Re: Check if an object is disposed?
« Reply #5 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.
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Kawa

Re: Check if an object is disposed?
« Reply #6 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.

Offline troflip

Re: Check if an object is disposed?
« Reply #7 on: April 04, 2016, 08:29:24 PM »
Yeah, makes sense for cutscenes.
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline MusicallyInspired

Re: Check if an object is disposed?
« Reply #8 on: April 04, 2016, 08:39:33 PM »
This is an introduction sequence.
Brass Lantern Prop Competition

Offline Kawa

Re: Check if an object is disposed?
« Reply #9 on: April 05, 2016, 03:36:29 AM »
No issues then :3

Offline Cloudee1

Re: Check if an object is disposed?
« Reply #10 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
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.03 seconds with 24 queries.