Close a game without leaking memory. It should be noted that sending an SDL Quit event leaks memory hedgeroid
authorXeli
Fri, 07 Oct 2011 14:17:07 +0200
branchhedgeroid
changeset 6035 bdd0528ee8a6
parent 6033 6bcc36225162
child 6037 8cdc7bc3e38c
Close a game without leaking memory. It should be noted that sending an SDL Quit event leaks memory
hedgewars/PascalExports.pas
hedgewars/hwLibrary.pas
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/PascalExports.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/SDLActivity.java
--- a/hedgewars/PascalExports.pas	Tue Oct 04 19:20:42 2011 +0200
+++ b/hedgewars/PascalExports.pas	Fri Oct 07 14:17:07 2011 +0200
@@ -35,6 +35,7 @@
 function HW_getNumberOfWeapons:LongInt; cdecl; export;
 function HW_getMaxNumberOfTeams:LongInt; cdecl; export;
 function HW_getMaxNumberOfHogs:LongInt; cdecl; export;
+procedure HW_terminate(closeFrontend: Boolean); cdecl; export;
 
 implementation
 {$IFDEF HWLIBRARY}
--- a/hedgewars/hwLibrary.pas	Tue Oct 04 19:20:42 2011 +0200
+++ b/hedgewars/hwLibrary.pas	Fri Oct 07 14:17:07 2011 +0200
@@ -50,7 +50,8 @@
     GenLandPreview name Java_Prefix + 'GenLandPreview',
     HW_getNumberOfweapons name Java_Prefix + 'HWgetNumberOfWeapons',
     HW_getMaxNumberOfHogs name Java_Prefix + 'HWgetMaxNumberOfHogs',
-    HW_getMaxNumberOfTeams name Java_Prefix + 'HWgetMaxNumberOfTeams';
+    HW_getMaxNumberOfTeams name Java_Prefix + 'HWgetMaxNumberOfTeams',
+    HW_terminate name Java_Prefix + 'HWterminate';
 {$ENDIF}
 
 begin
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/PascalExports.java	Tue Oct 04 19:20:42 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/PascalExports.java	Fri Oct 07 14:17:07 2011 +0200
@@ -36,5 +36,5 @@
 	public static native int HWgetNumberOfWeapons();
 	public static native int HWgetMaxNumberOfTeams();
 	public static native int HWgetMaxNumberOfHogs();
-	
+        public static native int HWterminate(boolean b);	
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/SDLActivity.java	Tue Oct 04 19:20:42 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/SDLActivity.java	Fri Oct 07 14:17:07 2011 +0200
@@ -8,6 +8,7 @@
 
 import org.hedgewars.mobile.EngineProtocol.EngineProtocolNetwork;
 import org.hedgewars.mobile.EngineProtocol.GameConfig;
+import org.hedgewars.mobile.EngineProtocol.PascalExports;
 import org.hedgewars.mobile.TouchInterface.TouchInterface;
 
 import android.app.Activity;
@@ -346,7 +347,8 @@
 		Log.v("SDL", "surfaceDestroyed()");
 
 		// Send a quit message to the application
-		SDLActivity.nativeQuit();
+		//SDLActivity.nativeQuit();
+                PascalExports.HWterminate(true);
 
 		// Now wait for the SDL thread to quit
 		if (mSDLThread != null) {
@@ -520,7 +522,7 @@
 		if (event.getAction() == KeyEvent.ACTION_DOWN) {
 			Log.v("SDL", "key down: " + keyCode);
 			if(keyCode == KeyEvent.KEYCODE_BACK){//TODO ask user to quit or not
-				SDLActivity.nativeQuit();
+				PascalExports.HWterminate(true);
 				//SDLActivity.mSingleton.finish();
 			}else{
 				SDLActivity.onNativeKeyDown(keyCode);