Hedgeroid: Fixed map preview again (might be a JNA bug)
authorMedo <smaxein@googlemail.com>
Thu, 23 Aug 2012 19:47:38 +0200
changeset 7590 0be267033fb3
parent 7588 27e5857da6af
child 7613 ce6ead3327b2
Hedgeroid: Fixed map preview again (might be a JNA bug)
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/Frontlib.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/Frontlib.java	Thu Aug 23 18:28:33 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/Frontlib.java	Thu Aug 23 19:47:38 2012 +0200
@@ -334,7 +334,7 @@
 		}
 		
 		public static ByteArrayPtr createJavaOwned(byte[] buffer) {
-			if(buffer == null) {
+			if(buffer == null || buffer.length == 0) {
 				return null;
 			}
 			// no need for javaOwnedInstance here because PointerType
@@ -593,14 +593,24 @@
 			seed = map.seed;
 			theme = map.theme;
 			byte[] buf = map.getDrawData();
-			drawData = ByteArrayPtr.createJavaOwned(buf);
+			if(buf==null || buf.length==0) {
+				drawData = null;
+			} else {
+				drawData = ByteArrayPtr.createJavaOwned(buf).getPointer();
+			}
 			drawDataSize = NativeSizeT.valueOf(buf==null ? 0 : buf.length);
 			templateFilter = map.templateFilter;
 			mazeSize = map.mazeSize;
 		}
 		
 		public MapRecipe toMapRecipe() {
-			byte[] buf = ByteArrayPtr.deref(drawData, drawDataSize.intValue());
+			byte[] buf;
+			int size = drawDataSize.intValue();
+			if(size>0) {
+				buf = drawData.getByteArray(0, size);
+			} else {
+				buf = null;
+			}
 			return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, buf);
 		}
 		
@@ -608,7 +618,7 @@
 		public String name;
 		public String seed;
 		public String theme;
-		public ByteArrayPtr drawData;
+		public Pointer drawData;			// We can't use ByteArrayPtr in a struct because JNA will overwrite the value with NULL - probably a bug.
 		public NativeSizeT drawDataSize;
 		public int templateFilter;
 		public int mazeSize;