Ported: Fix issue causing the project manager to crash because of missing path argument

In the process, the initialization logic is updated to show an error message and gracefully close the engine when setup errors occur.
- m4gr3d
4be7c91cd9
This commit is contained in:
Relintai 2022-09-17 17:27:50 +02:00
parent 6e97e0c485
commit 6b9e851e5c
6 changed files with 42 additions and 10 deletions

View File

@ -2926,8 +2926,13 @@ void EditorNode::_discard_changes(const String &p_str) {
String exec = OS::get_singleton()->get_executable_path(); String exec = OS::get_singleton()->get_executable_path();
List<String> args; List<String> args;
args.push_back("--path");
args.push_back(exec.get_base_dir()); String exec_base_dir = exec.get_base_dir();
if (!exec_base_dir.empty()) {
args.push_back("--path");
args.push_back(exec_base_dir);
}
args.push_back("--project-manager"); args.push_back("--project-manager");
OS::ProcessID pid = 0; OS::ProcessID pid = 0;

View File

@ -12,6 +12,8 @@
<string name="text_button_resume">Resume Download</string> <string name="text_button_resume">Resume Download</string>
<string name="text_button_cancel">Cancel</string> <string name="text_button_cancel">Cancel</string>
<string name="text_button_cancel_verify">Cancel Verification</string> <string name="text_button_cancel_verify">Cancel Verification</string>
<string name="text_error_title">Error!</string>
<string name="error_engine_setup_message">Unable to setup the Godot Engine! Aborting…</string>
<!-- APK Expansion Strings --> <!-- APK Expansion Strings -->

View File

@ -55,6 +55,7 @@ import android.content.SharedPreferences.Editor;
import android.content.pm.ConfigurationInfo; import android.content.pm.ConfigurationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.hardware.Sensor; import android.hardware.Sensor;
@ -69,6 +70,7 @@ import android.os.Looper;
import android.os.Messenger; import android.os.Messenger;
import android.os.VibrationEffect; import android.os.VibrationEffect;
import android.os.Vibrator; import android.os.Vibrator;
import android.util.Log;
import android.view.Display; import android.view.Display;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Surface; import android.view.Surface;
@ -86,6 +88,7 @@ import androidx.annotation.CallSuper;
import androidx.annotation.Keep; import androidx.annotation.Keep;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.google.android.vending.expansion.downloader.DownloadProgressInfo; import com.google.android.vending.expansion.downloader.DownloadProgressInfo;
@ -110,6 +113,8 @@ import java.util.Locale;
import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10;
public class Pandemonium extends Fragment implements SensorEventListener, IDownloaderClient { public class Pandemonium extends Fragment implements SensorEventListener, IDownloaderClient {
private static final String TAG = Pandemonium.class.getSimpleName();
static final int MAX_SINGLETONS = 64; static final int MAX_SINGLETONS = 64;
private IStub mDownloaderClientStub; private IStub mDownloaderClientStub;
private TextView mStatusText; private TextView mStatusText;
@ -372,7 +377,12 @@ public class Pandemonium extends Fragment implements SensorEventListener, IDownl
final String[] current_command_line = command_line; final String[] current_command_line = command_line;
mView.queueEvent(() -> { mView.queueEvent(() -> {
PandemoniumLib.setup(current_command_line); if (!PandemoniumLib.setup(current_command_line)) {
pandemonium_initialized = false;
Log.e(TAG, "Unable to setup the Pandemonium engine! Aborting...");
alert(R.string.error_engine_setup_message, R.string.text_error_title, this::forceQuit);
return;
}
// Must occur after PandemoniumLib.setup has completed. // Must occur after PandemoniumLib.setup has completed.
for (PandemoniumPlugin plugin : pluginRegistry.getAllPlugins()) { for (PandemoniumPlugin plugin : pluginRegistry.getAllPlugins()) {
@ -464,13 +474,27 @@ public class Pandemonium extends Fragment implements SensorEventListener, IDownl
} }
public void alert(final String message, final String title) { 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(); final Activity activity = getActivity();
runOnUiThread(() -> { runOnUiThread(() -> {
AlertDialog.Builder builder = new AlertDialog.Builder(activity); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(message).setTitle(title); builder.setMessage(message).setTitle(title);
builder.setPositiveButton( builder.setPositiveButton(
"OK", "OK",
(dialog, id) -> dialog.cancel()); (dialog, id) -> {
if (okCallback != null) {
okCallback.run();
}
dialog.cancel();
});
AlertDialog dialog = builder.create(); AlertDialog dialog = builder.create();
dialog.show(); dialog.show();
}); });

View File

@ -63,7 +63,7 @@ public class PandemoniumLib {
* Invoked on the GL thread to complete setup for the Pandemonium native layer logic. * Invoked on the GL thread to complete setup for the Pandemonium native layer logic.
* @param p_cmdline Command line arguments used to configure Pandemonium native layer components. * @param p_cmdline Command line arguments used to configure Pandemonium 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. * Invoked on the GL thread when the underlying Android surface has changed size.

View File

@ -168,7 +168,7 @@ JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_
} }
} }
JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline) { JNIEXPORT jboolean JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline) {
setup_android_thread(); setup_android_thread();
const char **cmdline = NULL; const char **cmdline = NULL;
@ -178,10 +178,10 @@ JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_
cmdlen = env->GetArrayLength(p_cmdline); cmdlen = env->GetArrayLength(p_cmdline);
if (cmdlen) { if (cmdlen) {
cmdline = (const char **)memalloc((cmdlen + 1) * sizeof(const char *)); cmdline = (const char **)memalloc((cmdlen + 1) * sizeof(const char *));
ERR_FAIL_NULL_MSG(cmdline, "Out of memory."); ERR_FAIL_NULL_V_MSG(cmdline, false, "Out of memory.");
cmdline[cmdlen] = NULL; cmdline[cmdlen] = NULL;
j_cmdline = (jstring *)memalloc(cmdlen * sizeof(jstring)); j_cmdline = (jstring *)memalloc(cmdlen * sizeof(jstring));
ERR_FAIL_NULL_MSG(j_cmdline, "Out of memory."); ERR_FAIL_NULL_V_MSG(j_cmdline, false, "Out of memory.");
for (int i = 0; i < cmdlen; i++) { for (int i = 0; i < cmdlen; i++) {
jstring string = (jstring)env->GetObjectArrayElement(p_cmdline, i); jstring string = (jstring)env->GetObjectArrayElement(p_cmdline, i);
@ -206,12 +206,13 @@ JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_
// Note: --help and --version return ERR_HELP, but this should be translated to 0 if exit codes are propagated. // Note: --help and --version return ERR_HELP, but this should be translated to 0 if exit codes are propagated.
if (err != OK) { if (err != OK) {
return; // should exit instead and print the error return false;
} }
java_class_wrapper = memnew(JavaClassWrapper(pandemonium_java->get_activity())); java_class_wrapper = memnew(JavaClassWrapper(pandemonium_java->get_activity()));
ClassDB::register_class<JNISingleton>(); ClassDB::register_class<JNISingleton>();
_initialize_java_modules(); _initialize_java_modules();
return true;
} }
JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_resize(JNIEnv *env, jclass clazz, jint width, jint height) { JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_resize(JNIEnv *env, jclass clazz, jint width, jint height) {

View File

@ -39,7 +39,7 @@ extern "C" {
JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_initialize(JNIEnv *env, jclass clazz, jobject p_activity, jobject p_pandemonium_instance, jobject p_asset_manager, jobject p_pandemonium_io, jobject p_net_utils, jobject p_directory_access_handler, jobject p_file_access_handler, jboolean p_use_apk_expansion); JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_initialize(JNIEnv *env, jclass clazz, jobject p_activity, jobject p_pandemonium_instance, jobject p_asset_manager, jobject p_pandemonium_io, jobject p_net_utils, jobject p_directory_access_handler, jobject p_file_access_handler, jboolean p_use_apk_expansion);
JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_ondestroy(JNIEnv *env, jclass clazz); JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_ondestroy(JNIEnv *env, jclass clazz);
JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline); JNIEXPORT jboolean JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline);
JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_resize(JNIEnv *env, jclass clazz, jint width, jint height); JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_resize(JNIEnv *env, jclass clazz, jint width, jint height);
JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_newcontext(JNIEnv *env, jclass clazz); JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_newcontext(JNIEnv *env, jclass clazz);
JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_step(JNIEnv *env, jclass clazz); JNIEXPORT void JNICALL Java_net_relintai_pandemonium_pandemonium_PandemoniumLib_step(JNIEnv *env, jclass clazz);