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;
~ChartPlayer() {
Dispose();
}
public void Dispose() {
if (loadThread != null) loadThread.Abort();
if (texLoader != null) texLoader.Dispose();
}
#region MonoBehaviour
void Start() {
var logobj = GameObject.Find("Logs");
@@ -99,6 +90,19 @@ namespace Cryville.Crtr {
// 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;
diag::Stopwatch texloadtimer = new diag::Stopwatch();
bool firstFrame;
@@ -394,15 +398,11 @@ namespace Cryville.Crtr {
public void Stop() {
try {
Logger.Log("main", 1, "Game", "Stopping");
chart = null;
Game.AudioSession = Game.AudioSequencer.NewSession();
if (cbus != null) cbus.Dispose();
if (bbus != null) bbus.Dispose();
if (tbus != null) tbus.Dispose();
if (nbus != null) nbus.Dispose();
inputProxy.Deactivate();
foreach (var t in texs) Texture.Destroy(t.Value);
Camera.onPostRender -= OnCameraPostRender;
if (cbus != null) { cbus.Dispose(); cbus = null; }
if (bbus != null) { bbus.Dispose(); bbus = null; }
if (tbus != null) { tbus.Dispose(); tbus = null; }
if (nbus != null) { nbus.Dispose(); nbus = null; }
Logger.Log("main", 1, "Game", "Stopped");
}
catch (Exception ex) {
@@ -511,11 +511,15 @@ namespace Cryville.Crtr {
}
}
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");
cbus.DoPatch();
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)");
bbus = cbus.Clone(1, -clippingDist);

View File

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