Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmachine committed Jun 30, 2022
2 parents c08603d + b3fd53a commit bcc565f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion GameData/KSPCommunityFixes/KSPCommunityFixes.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"NAME": "KSPCommunityFixes",
"URL": "https://raw.githubusercontent.com/KSPModdingLibs/KSPCommunityFixes/master/GameData/KSPCommunityFixes/KSPCommunityFixes.version",
"DOWNLOAD": "https://github.com/KSPModdingLibs/KSPCommunityFixes/releases",
"VERSION": {"MAJOR": 1, "MINOR": 18, "PATCH": 1, "BUILD": 0},
"VERSION": {"MAJOR": 1, "MINOR": 18, "PATCH": 2, "BUILD": 0},
"KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 3},
"KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 8, "PATCH": 0},
"KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 3}
Expand Down
23 changes: 23 additions & 0 deletions KSPCommunityFixes/Performance/MemoryLeaks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,29 @@ private void OnSceneUnloaded(Scene scene)
continue;
}

// ScenarioUpgradeableFacilities is using a pattern where it adds a onLevelWasLoaded callback from its OnDestroy() to clean up some
// static stuff on the next scene load, and it also remove the delegate from the event while doing so. So it's not actually a leak
// and we add a specific case to exclude it.
if (gameEvent is EventData<GameScenes> onLevelWasLoaded && onLevelWasLoaded.eventName == "onNewGameLevelLoadRequestWasSanctionedAndActioned")
{
gameEventsCallbacksCount += onLevelWasLoaded.events.Count;
for (int i = onLevelWasLoaded.events.Count; i-- > 0;)
{
if (onLevelWasLoaded.events[i].originator is UnityEngine.Object unityObject && unityObject.IsDestroyed() && !(unityObject is ScenarioUpgradeableFacilities))
{
if (logDestroyedUnityObjectGameEventsLeaks)
{
Debug.Log($"[KSPCF:MemoryLeaks] Removed a {gameEvent.EventName} GameEvents callback owned by a destroyed {unityObject.GetType().FullName} instance");
}
onLevelWasLoaded.events.RemoveAt(i);
leakCount++;
gameEventsCallbacksCount--;
}
}

continue;
}

// general case for all others GameEvent types
try
{
Expand Down
2 changes: 1 addition & 1 deletion KSPCommunityFixes/Performance/SceneLoadSpeedBoost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private static void CachePersistentSFS(string saveFileName, string saveFolder, C

gameNode.SetValue(VALUENAME_TIMESTAMP, lastPersistentSerializedTimestamp, true);
#if DEBUG
Debug.Log($"[SceneLoadSpeedBoost] Persistent save cached\n{new StackTrace()}");
Debug.Log($"[SceneLoadSpeedBoost] Persistent save cached");
#endif
}
}
Expand Down
4 changes: 2 additions & 2 deletions KSPCommunityFixes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.18.1.0")]
[assembly: AssemblyFileVersion("1.18.1.0")]
[assembly: AssemblyVersion("1.18.2.0")]
[assembly: AssemblyFileVersion("1.18.2.0")]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ If doing so in the `Debug` configuration and if your KSP install is modified to

### Changelog

##### 1.18.2
- Fixed MemoryLeaks patch causing KSC facilities upgrades being reverted after a scene change.

##### 1.18.1
- Fixed AutostrutActions patch causing nullrefs on part duplication and generally not working as intended.

Expand Down

0 comments on commit bcc565f

Please sign in to comment.