瀏覽代碼

bugfix default depth buffer being disposed in MemoryManager.dispose()

ncannasse 7 年之前
父節點
當前提交
0360cf33fb
共有 3 個文件被更改,包括 10 次插入6 次删除
  1. 7 3
      h3d/impl/DirectXDriver.hx
  2. 2 2
      h3d/impl/MemoryManager.hx
  3. 1 1
      h3d/mat/DepthBuffer.hx

+ 7 - 3
h3d/impl/DirectXDriver.hx

@@ -225,7 +225,7 @@ class DirectXDriver extends h3d.impl.Driver {
 		if( extraDepthInst != null ) @:privateAccess {
 		if( extraDepthInst != null ) @:privateAccess {
 			extraDepthInst.width = width;
 			extraDepthInst.width = width;
 			extraDepthInst.height = height;
 			extraDepthInst.height = height;
-			extraDepthInst.dispose();
+			if( extraDepthInst.b != null ) disposeDepthBuffer(extraDepthInst);
 			extraDepthInst.b = allocDepthBuffer(extraDepthInst);
 			extraDepthInst.b = allocDepthBuffer(extraDepthInst);
 		}
 		}
 	}
 	}
@@ -283,8 +283,12 @@ class DirectXDriver extends h3d.impl.Driver {
 	}
 	}
 
 
 	override function getDefaultDepthBuffer():h3d.mat.DepthBuffer {
 	override function getDefaultDepthBuffer():h3d.mat.DepthBuffer {
-		if( extraDepthInst == null )
-			extraDepthInst = new h3d.mat.DepthBuffer(outputWidth, outputHeight);
+		if( extraDepthInst == null ) @:privateAccess {
+			extraDepthInst = new h3d.mat.DepthBuffer(0, 0);
+			extraDepthInst.width = outputWidth;
+			extraDepthInst.height = outputHeight;
+			allocDepthBuffer(extraDepthInst);
+		}
 		return extraDepthInst;
 		return extraDepthInst;
 	}
 	}
 
 

+ 2 - 2
h3d/impl/MemoryManager.hx

@@ -248,7 +248,7 @@ class MemoryManager {
 
 
 	@:allow(h3d.mat.Texture.dispose)
 	@:allow(h3d.mat.Texture.dispose)
 	function deleteTexture( t : h3d.mat.Texture ) {
 	function deleteTexture( t : h3d.mat.Texture ) {
-		textures.remove(t);
+		if( !textures.remove(t) ) return;
 		driver.disposeTexture(t);
 		driver.disposeTexture(t);
 		texMemory -= t.width * t.height * bpp(t);
 		texMemory -= t.width * t.height * bpp(t);
 	}
 	}
@@ -283,7 +283,7 @@ class MemoryManager {
 
 
 	@:allow(h3d.mat.DepthBuffer.dispose)
 	@:allow(h3d.mat.DepthBuffer.dispose)
 	function deleteDepth( b : h3d.mat.DepthBuffer ) {
 	function deleteDepth( b : h3d.mat.DepthBuffer ) {
-		depths.remove(b);
+		if( !depths.remove(b) ) return;
 		driver.disposeDepthBuffer(b);
 		driver.disposeDepthBuffer(b);
 		texMemory -= b.width * b.height * 4;
 		texMemory -= b.width * b.height * 4;
 	}
 	}

+ 1 - 1
h3d/mat/DepthBuffer.hx

@@ -16,7 +16,7 @@ class DepthBuffer {
 	public function new( width : Int, height : Int ) {
 	public function new( width : Int, height : Int ) {
 		this.width = width;
 		this.width = width;
 		this.height = height;
 		this.height = height;
-		if( width >= 0 ) alloc();
+		if( width > 0 ) alloc();
 	}
 	}
 
 
 	function alloc() {
 	function alloc() {