diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-08 09:19:25 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-08 09:19:25 +0200 |
commit | df5a356e6cfcf662052a8503a84c125427381781 (patch) | |
tree | f53ae96a926b72f46fdce0be6b3ae5cb60f484e5 /platform/android/java/lib/src/org | |
parent | 207c747ac0266e4c29528df83328cb2c7e2deda5 (diff) | |
parent | cd544fd86b0aca99bf31e6f0e3a248d3e4195d49 (diff) |
Merge pull request #65501 from m4gr3d/fix_invalid_project_manager_path_main
Fix issue causing the project manager to crash because of missing path argument
Diffstat (limited to 'platform/android/java/lib/src/org')
-rw-r--r-- | platform/android/java/lib/src/org/godotengine/godot/Godot.java | 35 | ||||
-rw-r--r-- | platform/android/java/lib/src/org/godotengine/godot/GodotLib.java | 4 |
2 files changed, 31 insertions, 8 deletions
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java index 6ebe7e4ee9..a75c69484c 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java @@ -57,6 +57,7 @@ import android.content.SharedPreferences.Editor; import android.content.pm.ConfigurationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.Resources; import android.graphics.Point; import android.graphics.Rect; import android.hardware.Sensor; @@ -69,6 +70,7 @@ import android.os.Environment; import android.os.Messenger; import android.os.VibrationEffect; import android.os.Vibrator; +import android.util.Log; import android.view.Display; import android.view.LayoutInflater; import android.view.Surface; @@ -85,6 +87,8 @@ import android.widget.TextView; import androidx.annotation.CallSuper; import androidx.annotation.Keep; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; import androidx.fragment.app.Fragment; import com.google.android.vending.expansion.downloader.DownloadProgressInfo; @@ -105,6 +109,8 @@ import java.util.List; import java.util.Locale; public class Godot extends Fragment implements SensorEventListener, IDownloaderClient { + private static final String TAG = Godot.class.getSimpleName(); + private IStub mDownloaderClientStub; private TextView mStatusText; private TextView mProgressFraction; @@ -250,7 +256,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC * Used by the native code (java_godot_lib_jni.cpp) to complete initialization of the GLSurfaceView view and renderer. */ @Keep - private void onVideoInit() { + private boolean onVideoInit() { final Activity activity = getActivity(); containerLayout = new FrameLayout(activity); containerLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); @@ -262,7 +268,11 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC // ...add to FrameLayout containerLayout.addView(editText); - GodotLib.setup(command_line); + if (!GodotLib.setup(command_line)) { + Log.e(TAG, "Unable to setup the Godot engine! Aborting..."); + alert(R.string.error_engine_setup_message, R.string.text_error_title, this::forceQuit); + return false; + } final String videoDriver = GodotLib.getGlobal("rendering/driver/driver_name"); if (videoDriver.equals("vulkan")) { @@ -303,6 +313,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC } } } + return true; } public void setKeepScreenOn(final boolean p_enabled) { @@ -344,13 +355,27 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC } public void alert(final String message, final String title) { + alert(message, title, null); + } + + private void alert(@StringRes int messageResId, @StringRes int titleResId, @Nullable Runnable okCallback) { + Resources res = getResources(); + alert(res.getString(messageResId), res.getString(titleResId), okCallback); + } + + private void alert(final String message, final String title, @Nullable Runnable okCallback) { final Activity activity = getActivity(); runOnUiThread(() -> { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setMessage(message).setTitle(title); builder.setPositiveButton( "OK", - (dialog, id) -> dialog.cancel()); + (dialog, id) -> { + if (okCallback != null) { + okCallback.run(); + } + dialog.cancel(); + }); AlertDialog dialog = builder.create(); dialog.show(); }); @@ -471,7 +496,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); - GodotLib.initialize(activity, + godot_initialized = GodotLib.initialize(activity, this, activity.getAssets(), io, @@ -482,8 +507,6 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC tts); result_callback = null; - - godot_initialized = true; } @Override diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java index d4fa12ed15..26aad867b1 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java @@ -54,7 +54,7 @@ public class GodotLib { /** * Invoked on the main thread to initialize Godot native layer. */ - public static native void initialize(Activity activity, + public static native boolean initialize(Activity activity, Godot p_instance, AssetManager p_asset_manager, GodotIO godotIO, @@ -74,7 +74,7 @@ public class GodotLib { * Invoked on the GL thread to complete setup for the Godot native layer logic. * @param p_cmdline Command line arguments used to configure Godot native layer components. */ - public static native void setup(String[] p_cmdline); + public static native boolean setup(String[] p_cmdline); /** * Invoked on the GL thread when the underlying Android surface has changed size. |