Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Resolve issue where the Godot app remains stuck when resuming. #51584

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.util.Log;

import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

/**
Expand All @@ -46,19 +47,42 @@
* within an Android app.
*/
public abstract class FullScreenGodotApp extends FragmentActivity implements GodotHost {
private static final String TAG = FullScreenGodotApp.class.getSimpleName();

@Nullable
private Godot godotFragment;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.godot_app_layout);
godotFragment = initGodotInstance();
if (godotFragment == null) {
throw new IllegalStateException("Godot instance must be non-null.");

Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.godot_fragment_container);
if (currentFragment instanceof Godot) {
Log.v(TAG, "Reusing existing Godot fragment instance.");
godotFragment = (Godot)currentFragment;
} else {
Log.v(TAG, "Creating new Godot fragment instance.");
godotFragment = initGodotInstance();
if (godotFragment == null) {
throw new IllegalStateException("Godot instance must be non-null.");
}

getSupportFragmentManager().beginTransaction().replace(R.id.godot_fragment_container, godotFragment).setPrimaryNavigationFragment(godotFragment).commitNowAllowingStateLoss();
}
}

getSupportFragmentManager().beginTransaction().replace(R.id.godot_fragment_container, godotFragment).setPrimaryNavigationFragment(godotFragment).commitNowAllowingStateLoss();
@Override
public void onDestroy() {
super.onDestroy();
onGodotForceQuit(godotFragment);
}

@Override
public final void onGodotForceQuit(Godot instance) {
if (instance == godotFragment) {
System.exit(0);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,6 @@ public void onDestroy() {

super.onDestroy();

// TODO: This is a temp solution. The proper fix will involve tracking down and properly shutting down each
// native Godot components that is started in Godot#onVideoInit.
forceQuit();
}

Expand Down Expand Up @@ -960,7 +958,11 @@ public final void runOnUiThread(@NonNull Runnable action) {
}

private void forceQuit() {
System.exit(0);
// TODO: This is a temp solution. The proper fix will involve tracking down and properly shutting down each
// native Godot components that is started in Godot#onVideoInit.
if (godotHost != null) {
godotHost.onGodotForceQuit(this);
}
}

private boolean obbIsCorrupted(String f, String main_pack_md5) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ default void onGodotSetupCompleted() {}
* Invoked on the render thread when the Godot main loop has started.
*/
default void onGodotMainLoopStarted() {}

/**
* Invoked on the UI thread as the last step of the Godot instance clean up phase.
*/
default void onGodotForceQuit(Godot instance) {}
}