Project

General

Profile

Bug #9843

VesselModule.OnSave does not fire after docking and undocking in the same scene

Added by MOARdV almost 8 years ago. Updated almost 8 years ago.

Status:
Closed
Severity:
Normal
Assignee:
-
Category:
Gameplay
Target version:
-
Start date:
06/04/2016
% Done:

100%

Version:
Platform:
Windows
Expansion:
Language:
English (US)
Mod Related:
No
Votes:
Arrow u r green
Arrow d r red

Description

I've been chasing bugs in VesselModule related to docking and undocking. The situation is convoluted, so please bear with me:

Two vessels (vessel A and vessel B) dock. The onPartCouple callback fires, and the two craft are merged into whichever Vessel was the "to" vessel in the callback (let's say it's vessel B, and A is the "from" vessel).

Once this happens, OnDestroy fires for vessel A. The VesselModule sees this, and any references it had to the Vessel become null. However, the VesselModule is not destroyed - it continues to fire during FixedUpdate, for instance.

If the player undocks these two craft without leaving the flight scene, the "zombie" VesselModule that was on vessel A sees an onVesselCreate callback, and it is now assigned to this new vessel (vessel C).

This is all fine and dandy, but... Upon leaving the flight scene, VesselModule.OnSave is not called for vessel C (the recycled VesselModule originally from vessel A), so any values that should have been saved are lost. The VesselModule also never sees an OnVesselDestroy callback before it is destroyed, although the VM from vessel B does.

I don't know if there's a reason the VesselModule from A doesn't get destroyed with its craft - the only reference to it I keep is in a static dictionary, and when the craft's OnVesselDestroy event fires, I remove it from that dictionary. Since it is later attached to a new vessel, I assume that it's being kept around on purpose. However, something in it doesn't get reset, so it doesn't see some key events later in the session.

History

#1 Updated by MOARdV almost 8 years ago

An additional note: after several dock / undock events in the same scene, the save file no longer has any vessels listed. They vanish.

#2 Updated by hvacengi almost 8 years ago

I wish that I could remember where I found this, but in kOS I found that I had to manually call `Destroy(this)` on the "from" vessel module to get it to properly release all of the KSP events, even though `OnDestroy` appeared to fire correctly. My issue seemed to be that a new `VesselModule` was created when undocking, but the events were still re-directed to the old vessel module, causing it not actually control steering on the recently undocked vessel.

#3 Updated by TriggerAu almost 8 years ago

  • Status changed from New to Needs Clarification

#4 Updated by MOARdV almost 8 years ago

  • Status changed from Needs Clarification to Resolved
  • % Done changed from 0 to 100

As I recall, I eventually determined that the specific failure I reported here was because the VesselModule persisted, so I never unsubscribed from some events (like OnVesselSave) with the orphaned VM, which ended triggering an exception that disrupted the save process. I'm closing this as 'resolved', since it was a combination of programmer error (mine) and undocumented / unexpected behavior with the VesselModule.

#5 Updated by TriggerAu almost 8 years ago

  • Status changed from Resolved to Closed

Thanks MOARdV

Also available in: Atom PDF