Fixed nullref caused when an entry in _targets was null

Fixed memory leak caused by the OnDestroy() methods not being called
	due to them being virtual
This commit is contained in:
Jonathan Bayer 2022-09-03 18:01:15 -04:00
parent 7e1b993d20
commit 14bc694588
4 changed files with 14 additions and 7 deletions

View File

@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file
| website | https://forum.kerbalspaceprogram.com/index.php?/topic/194802-18-111-conformal-decals | | website | https://forum.kerbalspaceprogram.com/index.php?/topic/194802-18-111-conformal-decals |
| author | Andrew Cassidy | | author | Andrew Cassidy |
## 0.2.11 - Unreleased, changes submitted by Linuxgurugamer
Fixed nullref caused when an entry in _targets was null
Fixed memory leak caused by the OnDestroy() methods not being called due to them being virtual
## 0.2.10 - 2022-03-14 ## 0.2.10 - 2022-03-14
### Fixed ### Fixed

View File

@ -283,7 +283,7 @@ namespace ConformalDecals {
} }
} }
public virtual void OnDestroy() { public void OnDestroy() {
// remove GameEvents // remove GameEvents
if (HighLogic.LoadedSceneIsEditor) { if (HighLogic.LoadedSceneIsEditor) {
GameEvents.onEditorPartEvent.Remove(OnEditorEvent); GameEvents.onEditorPartEvent.Remove(OnEditorEvent);
@ -577,7 +577,8 @@ namespace ConformalDecals {
// render on each target object // render on each target object
foreach (var target in _targets) { foreach (var target in _targets) {
target.Render(_decalMaterial, part.mpb, camera); if (target != null)
target.Render(_decalMaterial, part.mpb, camera);
} }
} }
} }

View File

@ -48,13 +48,13 @@ namespace ConformalDecals {
UpdateFlag(); UpdateFlag();
} }
public override void OnDestroy() { public void OnDestroy() {
if (HighLogic.LoadedSceneIsEditor) { if (HighLogic.LoadedSceneIsEditor) {
// Unregister flag change event // Unregister flag change event
GameEvents.onMissionFlagSelect.Remove(OnEditorFlagSelected); GameEvents.onMissionFlagSelect.Remove(OnEditorFlagSelected);
} }
base.OnDestroy(); //base.OnDestroy();
} }
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")] [KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")]

View File

@ -220,7 +220,7 @@ namespace ConformalDecals {
} }
} }
public override void OnDestroy() { public void OnDestroy() {
if (HighLogic.LoadedSceneIsGame && _currentText != null) TextRenderer.UnregisterText(_currentText); if (HighLogic.LoadedSceneIsGame && _currentText != null) TextRenderer.UnregisterText(_currentText);
// close all UIs // close all UIs
@ -228,7 +228,7 @@ namespace ConformalDecals {
if (_fillColorPickerController != null) _fillColorPickerController.Close(); if (_fillColorPickerController != null) _fillColorPickerController.Close();
if (_outlineColorPickerController != null) _outlineColorPickerController.Close(); if (_outlineColorPickerController != null) _outlineColorPickerController.Close();
base.OnDestroy(); //base.OnDestroy();
} }
protected override void OnDetach() { protected override void OnDetach() {