Fix OnDestroy not being called

This commit is contained in:
Andrew Cassidy 2022-10-30 21:03:27 -07:00
parent 2cca6c37bb
commit dfdf280564
4 changed files with 40 additions and 36 deletions

View File

@ -14,6 +14,10 @@ All notable changes to this project will be documented in this file
- Updated bundled Shabby to 0.3.0. Does not affect CKAN users - Updated bundled Shabby to 0.3.0. Does not affect CKAN users
### Fixed
- Reverted some changes from last version that were causing issues on launch
## 0.2.11 - 2022-10-30 ## 0.2.11 - 2022-10-30

View File

@ -122,8 +122,7 @@ namespace ConformalDecals {
if (materialProperties == null) { if (materialProperties == null) {
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>(); materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
} } else {
else {
materialProperties = ScriptableObject.Instantiate(materialProperties); materialProperties = ScriptableObject.Instantiate(materialProperties);
} }
} }
@ -153,14 +152,12 @@ namespace ConformalDecals {
if (backRenderer == null) { if (backRenderer == null) {
this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false."); this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false.");
updateBackScale = false; updateBackScale = false;
} } else {
else {
backMaterial = backRenderer.material; backMaterial = backRenderer.material;
if (backMaterial == null) { if (backMaterial == null) {
this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false."); this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false.");
updateBackScale = false; updateBackScale = false;
} } else {
else {
if (backTextureBaseScale == default) backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex); if (backTextureBaseScale == default) backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
} }
} }
@ -201,12 +198,10 @@ namespace ConformalDecals {
if (tileRect.x >= 0) { if (tileRect.x >= 0) {
materialProperties.UpdateTile(tileRect); materialProperties.UpdateTile(tileRect);
} } else if (tileIndex >= 0) {
else if (tileIndex >= 0) {
materialProperties.UpdateTile(tileIndex, tileSize); materialProperties.UpdateTile(tileIndex, tileSize);
} }
} } catch (Exception e) {
catch (Exception e) {
this.LogException("Exception parsing partmodule", e); this.LogException("Exception parsing partmodule", e);
} }
@ -222,8 +217,7 @@ namespace ConformalDecals {
if (HighLogic.LoadedSceneIsGame) { if (HighLogic.LoadedSceneIsGame) {
UpdateScale(); UpdateScale();
} } else {
else {
scale = defaultScale; scale = defaultScale;
depth = defaultDepth; depth = defaultDepth;
opacity = defaultOpacity; opacity = defaultOpacity;
@ -261,8 +255,7 @@ namespace ConformalDecals {
// set initial attachment state // set initial attachment state
if (part.parent == null) { if (part.parent == null) {
OnDetach(); OnDetach();
} } else {
else {
OnAttach(); OnAttach();
} }
} }
@ -283,7 +276,7 @@ namespace ConformalDecals {
} }
} }
public void OnDestroy() { public virtual void OnDestroy() {
// remove GameEvents // remove GameEvents
if (HighLogic.LoadedSceneIsEditor) { if (HighLogic.LoadedSceneIsEditor) {
GameEvents.onEditorPartEvent.Remove(OnEditorEvent); GameEvents.onEditorPartEvent.Remove(OnEditorEvent);
@ -440,11 +433,13 @@ namespace ConformalDecals {
// update projection // update projection
foreach (var target in _targets) { foreach (var target in _targets) {
if (target != null) if (target == null) {
_targets.Remove(target);
} else {
target.Project(_orthoMatrix, decalProjectorTransform, _boundsRenderer.bounds, useBaseNormal); target.Project(_orthoMatrix, decalProjectorTransform, _boundsRenderer.bounds, useBaseNormal);
} }
} }
else { } else {
// rescale preview model // rescale preview model
decalModelTransform.localScale = new Vector3(size.x, size.y, (size.x + size.y) / 2); decalModelTransform.localScale = new Vector3(size.x, size.y, (size.x + size.y) / 2);
@ -472,8 +467,7 @@ namespace ConformalDecals {
protected void UpdateTargets() { protected void UpdateTargets() {
if (_targets == null) { if (_targets == null) {
_targets = new List<ProjectionTarget>(); _targets = new List<ProjectionTarget>();
} } else {
else {
_targets.Clear(); _targets.Clear();
} }
@ -578,9 +572,12 @@ namespace ConformalDecals {
// render on each target object // render on each target object
foreach (var target in _targets) { foreach (var target in _targets) {
if (target != null) if (target == null) {
_targets.Remove(target);
} else {
target.Render(_decalMaterial, part.mpb, camera); target.Render(_decalMaterial, part.mpb, camera);
} }
} }
} }
} }
}

View File

@ -48,11 +48,13 @@ namespace ConformalDecals {
UpdateFlag(); UpdateFlag();
} }
public void OnDestroy() { public virtual 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();
} }
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")] [KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")]
@ -107,8 +109,7 @@ namespace ConformalDecals {
if (useCustomFlag) { if (useCustomFlag) {
// set the texture to the custom flag // set the texture to the custom flag
textureProperty.TextureUrl = flagUrl; textureProperty.TextureUrl = flagUrl;
} } else {
else {
// set the texture to the mission flag // set the texture to the mission flag
textureProperty.TextureUrl = MissionFlagUrl; textureProperty.TextureUrl = MissionFlagUrl;
} }

View File

@ -227,6 +227,8 @@ namespace ConformalDecals {
if (_textEntryController != null) _textEntryController.Close(); if (_textEntryController != null) _textEntryController.Close();
if (_fillColorPickerController != null) _fillColorPickerController.Close(); if (_fillColorPickerController != null) _fillColorPickerController.Close();
if (_outlineColorPickerController != null) _outlineColorPickerController.Close(); if (_outlineColorPickerController != null) _outlineColorPickerController.Close();
base.OnDestroy();
} }
protected override void OnDetach() { protected override void OnDetach() {