Skip to content

Commit fa9c940

Browse files
committed
Fix #79: destroy cameras when the MFD is destroyed
1 parent 2c52e7d commit fa9c940

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

RasterPropMonitor/Core/FlyingCamera.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -202,29 +202,19 @@ private bool CreateCameraObjects(string newCameraName = null)
202202
}
203203
}
204204

205-
private void CleanupCameraObjects()
205+
public void CleanupCameraObjects()
206206
{
207-
if (enabled)
207+
for (int i = 0; i < cameraObject.Length; i++)
208208
{
209-
for (int i = 0; i < cameraObject.Length; i++)
209+
if (cameraObject[i] != null)
210210
{
211-
try
212-
{
213-
UnityEngine.Object.Destroy(cameraObject[i]);
214-
// Analysis disable once EmptyGeneralCatchClause
215-
}
216-
catch
217-
{
218-
// Yes, that's really what it's supposed to be doing.
219-
}
220-
finally
221-
{
222-
cameraObject[i] = null;
223-
}
211+
UnityEngine.Object.Destroy(cameraObject[i]);
224212
}
225-
enabled = false;
226-
//JUtil.LogMessage(this, "Turning camera off.");
213+
214+
cameraObject[i] = null;
227215
}
216+
217+
enabled = false;
228218
cameraPart = null;
229219
cameraTransform = null;
230220
}

RasterPropMonitor/Handlers/JSISteerableCamera.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ public override void OnUpdate()
394394

395395
public void OnDestroy()
396396
{
397+
if (cameraObject != null)
398+
{
399+
cameraObject.CleanupCameraObjects();
400+
cameraObject = null;
401+
}
397402
if (homeCrosshairMaterial != null)
398403
{
399404
UnityEngine.Object.Destroy(homeCrosshairMaterial);

0 commit comments

Comments
 (0)