Fix chart player dispose.

This commit is contained in:
2022-11-15 17:29:10 +08:00
parent 35ac57bfba
commit a8ab73ac65
2 changed files with 112 additions and 108 deletions

View File

@@ -68,15 +68,6 @@ namespace Cryville.Crtr {
InputProxy inputProxy; InputProxy inputProxy;
~ChartPlayer() {
Dispose();
}
public void Dispose() {
if (loadThread != null) loadThread.Abort();
if (texLoader != null) texLoader.Dispose();
}
#region MonoBehaviour #region MonoBehaviour
void Start() { void Start() {
var logobj = GameObject.Find("Logs"); var logobj = GameObject.Find("Logs");
@@ -99,6 +90,19 @@ namespace Cryville.Crtr {
// Camera.main.RenderToCubemap(); // Camera.main.RenderToCubemap();
} }
void OnDestroy() {
if (cbus != null) cbus.Dispose();
if (bbus != null) bbus.Dispose();
if (tbus != null) tbus.Dispose();
if (nbus != null) nbus.Dispose();
if (loadThread != null) loadThread.Abort();
if (texLoader != null) texLoader.Dispose();
if (inputProxy != null) inputProxy.Dispose();
if (texs != null) foreach (var t in texs) Texture.Destroy(t.Value);
Camera.onPostRender -= OnCameraPostRender;
GC.Collect();
}
bool texloaddone; bool texloaddone;
diag::Stopwatch texloadtimer = new diag::Stopwatch(); diag::Stopwatch texloadtimer = new diag::Stopwatch();
bool firstFrame; bool firstFrame;
@@ -394,15 +398,11 @@ namespace Cryville.Crtr {
public void Stop() { public void Stop() {
try { try {
Logger.Log("main", 1, "Game", "Stopping"); Logger.Log("main", 1, "Game", "Stopping");
chart = null;
Game.AudioSession = Game.AudioSequencer.NewSession(); Game.AudioSession = Game.AudioSequencer.NewSession();
if (cbus != null) cbus.Dispose(); if (cbus != null) { cbus.Dispose(); cbus = null; }
if (bbus != null) bbus.Dispose(); if (bbus != null) { bbus.Dispose(); bbus = null; }
if (tbus != null) tbus.Dispose(); if (tbus != null) { tbus.Dispose(); tbus = null; }
if (nbus != null) nbus.Dispose(); if (nbus != null) { nbus.Dispose(); nbus = null; }
inputProxy.Deactivate();
foreach (var t in texs) Texture.Destroy(t.Value);
Camera.onPostRender -= OnCameraPostRender;
Logger.Log("main", 1, "Game", "Stopped"); Logger.Log("main", 1, "Game", "Stopped");
} }
catch (Exception ex) { catch (Exception ex) {
@@ -511,11 +511,15 @@ namespace Cryville.Crtr {
} }
} }
Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 1)"); Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 1)");
cbus.Clone(16).Forward(); using (var pbus = cbus.Clone(16)) {
pbus.Forward();
}
Logger.Log("main", 0, "Load/WorkerThread", "Patching events"); Logger.Log("main", 0, "Load/WorkerThread", "Patching events");
cbus.DoPatch(); cbus.DoPatch();
Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 2)"); Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 2)");
cbus.Clone(17).Forward(); using (var pbus = cbus.Clone(17)) {
pbus.Forward();
}
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 1)"); Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 1)");
bbus = cbus.Clone(1, -clippingDist); bbus = cbus.Clone(1, -clippingDist);

View File

@@ -196,7 +196,7 @@ namespace Cryville.Crtr.Event {
public void Dispose() { public void Dispose() {
if (Disposed) return; if (Disposed) return;
Disposed = true; Disposed = true;
if (Handler != null) Handler.Dispose(); if (CloneType < 16 && Handler != null) Handler.Dispose();
foreach (var s in Children) foreach (var s in Children)
s.Value.Dispose(); s.Value.Dispose();
RMVPool.ReturnAll(); RMVPool.ReturnAll();