KSPModdingLibs / KSPCommunityFixes

Community patches for bugs in the KSP codebase
49 stars 17 forks source link

AttachNodes seem to hold onto a reference to a previous part #203

Closed JonnyOThan closed 5 months ago

JonnyOThan commented 6 months ago

image

After loading a quicksave, the "top" attachnode on the root part of the vessel is pointing to a destroyed part.

JonnyOThan commented 6 months ago

I'm not really sure what's going on here - I fixed a few other memory leak issues in other mods and I'm not seeing this one anymore. I guess I'll reopen it if I spot it again.

JonnyOThan commented 6 months ago

Yeah there seems like something is going on here...

Repro steps:

  1. Create a craft in the VAB that is a single mk1pod or lander can
  2. Launch it
  3. Quicksave on the pad
  4. Load the quicksave

The loaded part's attachnode.owner field seems to be pointing to a destroyed copy of the part.

JonnyOThan commented 5 months ago

As gotmachine figured out, this only occurs on the root part because ProtoPartSnapShot.Load has some weird behavior for the root part since it's actually added to the vessel's gameobject. It can't just clone the part prefab. Instead it clones the prefab, adds the same components to the vessel, and copies their data. That means the attachnodes in the part are pointing to the clone which we are about to destroy.

This doesnt' seem like a huge deal since it's just leaking a copy of the prefab and not potentially a full vessel or anything that would have a lot of data attached to it.