mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
fix memory leaks caused by world not being properly disposed
This commit is contained in:
parent
628a2627ff
commit
0ae13d5acc
4 changed files with 44 additions and 11 deletions
|
|
@ -989,6 +989,7 @@ class DtsObject extends GameObject {
|
|||
|
||||
public override function dispose() {
|
||||
super.dispose();
|
||||
this.level = null;
|
||||
this.dtsResource.release();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,16 +13,25 @@ import h3d.scene.Object;
|
|||
import h3d.scene.Mesh;
|
||||
import h3d.scene.MeshBatch;
|
||||
|
||||
typedef MeshBatchInfo = {
|
||||
@:publicFields
|
||||
class MeshBatchInfo {
|
||||
var instances:Array<MeshInstance>;
|
||||
var meshbatch:MeshBatch;
|
||||
var ?transparencymeshbatch:MeshBatch;
|
||||
var transparencymeshbatch:MeshBatch;
|
||||
var mesh:Mesh;
|
||||
|
||||
public function new() {}
|
||||
}
|
||||
|
||||
typedef MeshInstance = {
|
||||
@:publicFields
|
||||
class MeshInstance {
|
||||
var emptyObj:Object;
|
||||
var gameObject:GameObject;
|
||||
|
||||
public function new(eo, go) {
|
||||
this.emptyObj = eo;
|
||||
this.gameObject = go;
|
||||
}
|
||||
}
|
||||
|
||||
class InstanceManager {
|
||||
|
|
@ -108,7 +117,7 @@ class InstanceManager {
|
|||
var objs = getAllChildren(object);
|
||||
var minfos = objects[objectMap.get(object.identifier)]; // objects.get(object.identifier);
|
||||
for (i in 0...objs.length) {
|
||||
minfos[i].instances.push({emptyObj: objs[i], gameObject: object});
|
||||
minfos[i].instances.push(new MeshInstance(objs[i], object));
|
||||
}
|
||||
} else {
|
||||
// First time appending the thing so bruh
|
||||
|
|
@ -117,11 +126,11 @@ class InstanceManager {
|
|||
var minfos = [];
|
||||
for (obj in objs) {
|
||||
var isMesh = obj is Mesh;
|
||||
var minfo:MeshBatchInfo = {
|
||||
instances: [{emptyObj: obj, gameObject: object}],
|
||||
meshbatch: isMesh ? new MeshBatch(cast(cast(obj, Mesh).primitive), cast(cast(obj, Mesh)).material.clone(), scene) : null,
|
||||
mesh: isMesh ? cast obj : null
|
||||
}
|
||||
var minfo:MeshBatchInfo = new MeshBatchInfo();
|
||||
minfo.instances = [new MeshInstance(obj, object)];
|
||||
minfo.meshbatch = isMesh ? new MeshBatch(cast(cast(obj, Mesh).primitive), cast(cast(obj, Mesh)).material.clone(), scene) : null;
|
||||
minfo.mesh = isMesh ? cast obj : null;
|
||||
|
||||
if (isMesh) {
|
||||
var mat = cast(obj, Mesh).material;
|
||||
var dtsshader = mat.mainPass.getShader(DtsTexture);
|
||||
|
|
|
|||
|
|
@ -194,10 +194,12 @@ class MarbleGame {
|
|||
}, (sender) -> {
|
||||
canvas.popDialog(exitGameDlg);
|
||||
paused = !paused;
|
||||
world.setCursorLock(true);
|
||||
var w = getWorld();
|
||||
w.setCursorLock(true);
|
||||
}, (sender) -> {
|
||||
canvas.popDialog(exitGameDlg);
|
||||
world.restart();
|
||||
var w = getWorld();
|
||||
w.restart();
|
||||
// world.setCursorLock(true);
|
||||
paused = !paused;
|
||||
});
|
||||
|
|
@ -211,6 +213,11 @@ class MarbleGame {
|
|||
}
|
||||
}
|
||||
|
||||
public function getWorld() {
|
||||
// So that we don't actually store this somewhere in any closure stack
|
||||
return world;
|
||||
}
|
||||
|
||||
public function quitMission() {
|
||||
world.setCursorLock(false);
|
||||
paused = false;
|
||||
|
|
|
|||
|
|
@ -1545,27 +1545,43 @@ class MarbleWorld extends Scheduler {
|
|||
for (interior in this.interiors) {
|
||||
interior.dispose();
|
||||
}
|
||||
interiors = null;
|
||||
for (pathedInteriors in this.pathedInteriors) {
|
||||
pathedInteriors.dispose();
|
||||
}
|
||||
pathedInteriors = null;
|
||||
for (marble in this.marbles) {
|
||||
marble.dispose();
|
||||
}
|
||||
marbles = null;
|
||||
for (dtsObject in this.dtsObjects) {
|
||||
dtsObject.dispose();
|
||||
}
|
||||
dtsObjects = null;
|
||||
for (trigger in this.triggers) {
|
||||
trigger.dispose();
|
||||
}
|
||||
triggers = null;
|
||||
for (soundResource in this.soundResources) {
|
||||
soundResource.release();
|
||||
}
|
||||
for (textureResource in this.textureResources) {
|
||||
textureResource.release();
|
||||
}
|
||||
gems = null;
|
||||
|
||||
sky.dispose();
|
||||
|
||||
instanceManager = null;
|
||||
collisionWorld = null;
|
||||
particleManager = null;
|
||||
namedObjects = null;
|
||||
shapeOrTriggerInside = null;
|
||||
shapeImmunity = null;
|
||||
currentCheckpoint = null;
|
||||
checkpointCollectedGems = null;
|
||||
marble = null;
|
||||
|
||||
this._disposed = true;
|
||||
AudioManager.stopAllSounds();
|
||||
AudioManager.playShell();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue