You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Fix the issue causing the Godot Android Editor to crash when returning from the launched and running game
The issue was caused because the running game pid was not set, and thus had a value of `0`. When trying to stop the running game, the `EditorRun::stop()` logic would kill the process with pid 0, which on Android corresponds to the running app's own process, thus causing the editor to crash. This issue did not happen on Godot 3 because pid with value of `0` are not considered valid.
This commit is contained in:
@@ -31,12 +31,11 @@
|
||||
package org.godotengine.editor
|
||||
|
||||
import android.Manifest
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Debug
|
||||
import android.os.Environment
|
||||
import android.os.*
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.window.layout.WindowMetricsCalculator
|
||||
@@ -64,11 +63,18 @@ open class GodotEditor : FullScreenGodotApp() {
|
||||
|
||||
private const val COMMAND_LINE_PARAMS = "command_line_params"
|
||||
|
||||
private const val EDITOR_ID = 777
|
||||
private const val EDITOR_ARG = "--editor"
|
||||
private const val EDITOR_ARG_SHORT = "-e"
|
||||
private const val EDITOR_PROCESS_NAME_SUFFIX = ":GodotEditor"
|
||||
|
||||
private const val GAME_ID = 667
|
||||
private const val GAME_PROCESS_NAME_SUFFIX = ":GodotGame"
|
||||
|
||||
private const val PROJECT_MANAGER_ID = 555
|
||||
private const val PROJECT_MANAGER_ARG = "--project-manager"
|
||||
private const val PROJECT_MANAGER_ARG_SHORT = "-p"
|
||||
private const val PROJECT_MANAGER_PROCESS_NAME_SUFFIX = ":GodotProjectManager"
|
||||
}
|
||||
|
||||
private val commandLineParams = ArrayList<String>()
|
||||
@@ -102,9 +108,10 @@ open class GodotEditor : FullScreenGodotApp() {
|
||||
|
||||
override fun getCommandLine() = commandLineParams
|
||||
|
||||
override fun onNewGodotInstanceRequested(args: Array<String>) {
|
||||
override fun onNewGodotInstanceRequested(args: Array<String>): Int {
|
||||
// Parse the arguments to figure out which activity to start.
|
||||
var targetClass: Class<*> = GodotGame::class.java
|
||||
var instanceId = GAME_ID
|
||||
|
||||
// Whether we should launch the new godot instance in an adjacent window
|
||||
// https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT
|
||||
@@ -115,12 +122,14 @@ open class GodotEditor : FullScreenGodotApp() {
|
||||
if (EDITOR_ARG == arg || EDITOR_ARG_SHORT == arg) {
|
||||
targetClass = GodotEditor::class.java
|
||||
launchAdjacent = false
|
||||
instanceId = EDITOR_ID
|
||||
break
|
||||
}
|
||||
|
||||
if (PROJECT_MANAGER_ARG == arg || PROJECT_MANAGER_ARG_SHORT == arg) {
|
||||
targetClass = GodotProjectManager::class.java
|
||||
launchAdjacent = false
|
||||
instanceId = PROJECT_MANAGER_ID
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -139,6 +148,37 @@ open class GodotEditor : FullScreenGodotApp() {
|
||||
Log.d(TAG, "Starting $targetClass")
|
||||
startActivity(newInstance)
|
||||
}
|
||||
return instanceId
|
||||
}
|
||||
|
||||
override fun onGodotForceQuit(godotInstanceId: Int): Boolean {
|
||||
val processNameSuffix = when (godotInstanceId) {
|
||||
GAME_ID -> {
|
||||
GAME_PROCESS_NAME_SUFFIX
|
||||
}
|
||||
EDITOR_ID -> {
|
||||
EDITOR_PROCESS_NAME_SUFFIX
|
||||
}
|
||||
PROJECT_MANAGER_ID -> {
|
||||
PROJECT_MANAGER_PROCESS_NAME_SUFFIX
|
||||
}
|
||||
else -> ""
|
||||
}
|
||||
if (processNameSuffix.isBlank()) {
|
||||
return false
|
||||
}
|
||||
|
||||
val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
val runningProcesses = activityManager.runningAppProcesses
|
||||
for (runningProcess in runningProcesses) {
|
||||
if (runningProcess.processName.endsWith(processNameSuffix)) {
|
||||
Log.v(TAG, "Killing Godot process ${runningProcess.processName}")
|
||||
Process.killProcess(runningProcess.pid)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Get the screen's density scale
|
||||
|
||||
Reference in New Issue
Block a user