hedgeroid: fix needlessly creating netplay instance on check for "connecting..." hedgeroid
authorsheepluva
Sat, 07 Dec 2019 16:14:27 +0100
branchhedgeroid
changeset 15511 fb23e49b2d4e
parent 15510 7030706266df
child 15512 45d6806548e9
hedgeroid: fix needlessly creating netplay instance on check for "connecting..."
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Netplay.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java	Fri Dec 06 22:20:53 2019 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java	Sat Dec 07 16:14:27 2019 +0100
@@ -103,10 +103,14 @@
         broadcastManager.unregisterReceiver(connectedReceiver);
         broadcastManager.unregisterReceiver(connectionFailedReceiver);
         broadcastManager.unregisterReceiver(passwordRequestedReceiver);
-        Netplay netplay = Netplay.getAppInstance(getApplicationContext());
-        if(netplay.getState() == State.CONNECTING) {
-            netplay.disconnect();
+        // disable netplay for now
+        if (Netplay.hasAppInstance()) {
+            Netplay netplay = Netplay.getAppInstance(getApplicationContext());
+            if(netplay.getState() == State.CONNECTING) {
+                netplay.disconnect();
+            }
         }
+
     }
 
     @Override
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Netplay.java	Fri Dec 06 22:20:53 2019 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Netplay.java	Sat Dec 07 16:14:27 2019 +0100
@@ -188,6 +188,10 @@
 
     private static Netplay instance;
 
+    public static boolean hasAppInstance() {
+        return instance != null;
+    }
+
     /**
      * Retrieve the single app-wide instance of the netplay interface, creating it if it
      * does not exist yet.
@@ -196,7 +200,7 @@
      * @return
      */
     public static Netplay getAppInstance(Context applicationContext) {
-        if(instance == null) {
+        if (!hasAppInstance()) {
             // We will need some default values for rooms, best load them here
             Scheme defaultScheme = null;
             Weaponset defaultWeaponset = null;