Jump to content

How to detect when a vessel you just queried for is now gone.


Recommended Posts

Imagine code that's doing this:

Up front, it queries FlightGlobals.vessels, and goes through it looking for a subset of the list of vessels matching a criteria. It stores that list.

Now the mod has some variables which are references to vessels.

In the next update, it starts working on that list of vessels. But there's a timing issue. One of them might have just gone away and been blown up. But the vessel handle won't be null. It will now refer to a stale vessel which SQUAD has cleaned of most of its useful stuff (so most method calls on it will blow up with exceptions), and the only reason the vessel is even still there is because of my code's reference keeping it from getting orphaned.

I'd like to drop the vessel from the list by detecting that it now refers to a vessel that's been disconnected from the rest of the data structures and is now floating off in space wanting me to orphan it.

What's the API to detect that state? To detect "this vessel isn't a real vessel anymore. Don't try to use it."

Is it Vessel.state == Vessel.State.Dead? Is that the meaning of "dead" there or does "dead" mean something else?

Link to comment
Share on other sites

Anatid supplied an update to the Distant Object Enhancement to do that. Take a look in FlareDraw.cs for the calls to RemoveVesselFlare(). One piece of code in particular:


GameEvents.onVesselWillDestroy.Add(RemoveVesselFlare);

(where RemoveVesselFlare is a callback function). It looks like you need to proactively remove the vessel from your references to get rid of it.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...