Browse Source

improve Android SDLActivity to check for no shared libraries found when loading and alert instead of null crashing

Christopher Augustus 8 years ago
parent
commit
04f393c5a7
1 changed files with 23 additions and 19 deletions
  1. 23 19
      Android/src/org/libsdl/app/SDLActivity.java

+ 23 - 19
Android/src/org/libsdl/app/SDLActivity.java

@@ -126,27 +126,31 @@ public class SDLActivity extends Activity {
                     return filename.matches("^lib.*\\.so$");
                     return filename.matches("^lib.*\\.so$");
                 }
                 }
             });
             });
-            Arrays.sort(files, new Comparator<File>() {
-                @Override
-                public int compare(File lhs, File rhs) {
-                    return Long.valueOf(lhs.lastModified()).compareTo(rhs.lastModified());
+            String errorMsgBrokenLib = "";
+            if (files == null) {
+                errorMsgBrokenLib = "no libraries found in path \"" + libraryPath + "\"";
+            } else {
+                Arrays.sort(files, new Comparator<File>() {
+                    @Override
+                    public int compare(File lhs, File rhs) {
+                        return Long.valueOf(lhs.lastModified()).compareTo(rhs.lastModified());
+                    }
+                });
+                ArrayList<String> libraryNames = new ArrayList<String>(files.length);
+                for (final File libraryFilename : files) {
+                    String name = libraryFilename.getName().replaceAll("^lib(.*)\\.so$", "$1");
+                    libraryNames.add(name);
                 }
                 }
-            });
-            ArrayList<String> libraryNames = new ArrayList<String>(files.length);
-            for (final File libraryFilename : files) {
-                String name = libraryFilename.getName().replaceAll("^lib(.*)\\.so$", "$1");
-                libraryNames.add(name);
-            }
 
 
-            // Load shared libraries
-            String errorMsgBrokenLib = "";
-            try {
-                if (onLoadLibrary(libraryNames))
-                    mIsSharedLibraryLoaded = true;
-            } catch(UnsatisfiedLinkError e) {
-                errorMsgBrokenLib = e.getMessage();
-            } catch(Exception e) {
-                errorMsgBrokenLib = e.getMessage();
+                // Load shared libraries
+                try {
+                    if (onLoadLibrary(libraryNames))
+                        mIsSharedLibraryLoaded = true;
+                } catch(UnsatisfiedLinkError e) {
+                    errorMsgBrokenLib = e.getMessage();
+                } catch(Exception e) {
+                    errorMsgBrokenLib = e.getMessage();
+                }
             }
             }
 
 
             if (!errorMsgBrokenLib.isEmpty())
             if (!errorMsgBrokenLib.isEmpty())