ncannasse 7 年之前
父节点
当前提交
520217b556
共有 2 个文件被更改,包括 14 次插入4 次删除
  1. 1 1
      h3d/scene/pbr/VolumetricLightmap.hx
  2. 13 3
      hxd/prefab/ContextShared.hx

+ 1 - 1
h3d/scene/pbr/VolumetricLightmap.hx

@@ -102,7 +102,7 @@ class VolumetricLightmap extends h3d.scene.Mesh {
 	public function load( bytes : haxe.io.Bytes ) {
 		if( bytes.length == 0 )
 			return false;
-		bytes = haxe.zip.Uncompress.run(bytes);
+		bytes = try haxe.zip.Uncompress.run(bytes) catch( e : Dynamic ) throw e;
 		var count = getProbeCount();
 		if( bytes.length != count * getCoefCount() * 4 * 4 )
 			return false;

+ 13 - 3
hxd/prefab/ContextShared.hx

@@ -94,8 +94,10 @@ class ContextShared {
 			bytes.writeInt32(headerSize);
 			bytes.writeInt32(bakedData.get(name).length);
 		}
-		for( name in keys )
+		for( name in keys ) {
 			bytes.write(bakedData.get(name));
+			bytes.writeByte(0xFE); // stop
+		}
 		saveBakedFile(bytes.getBytes());
 	}
 
@@ -128,6 +130,8 @@ class ContextShared {
 			var bytesLen = data.getInt32(pos);
 			pos += 4;
 			bakedData.set(name,data.sub(bytesPos,bytesLen));
+			if( data.get(bytesPos+bytesLen) != 0xFE )
+				throw "Corrupted bake file";
 		}
 	}
 
@@ -144,7 +148,10 @@ class ContextShared {
 	}
 
 	public function getObjects<T:h3d.scene.Object>( p : Prefab, c: Class<T> ) : Array<T> {
-		var root = contexts.get(p).local3d;
+		var ctx = contexts.get(p);
+		if( ctx == null )
+			return [];
+		var root = ctx.local3d;
 		var childObjs = getChildrenRoots(root, p, []);
 		var ret = [];
 		function rec(o : h3d.scene.Object) {
@@ -159,7 +166,10 @@ class ContextShared {
 	}
 
 	public function getMaterials( p : Prefab ) {
-		var root = contexts.get(p).local3d;
+		var ctx = contexts.get(p);
+		if( ctx == null )
+			return [];
+		var root = ctx.local3d;
 		var childObjs = getChildrenRoots(root, p, []);
 		var ret = [];
 		function rec(o : h3d.scene.Object) {