-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Fix create_instance in android GodotApp so non-editor apps can restart #101050
Merged
Repiteo
merged 1 commit into
godotengine:master
from
jamie-pate:fix_android_godot_app_create_instance
Jan 22, 2025
+79
−31
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,8 +71,6 @@ abstract class BaseGodotEditor : GodotActivity() { | |
|
||
private const val WAIT_FOR_DEBUGGER = false | ||
|
||
@JvmStatic | ||
protected val EXTRA_COMMAND_LINE_PARAMS = "command_line_params" | ||
@JvmStatic | ||
protected val EXTRA_PIP_AVAILABLE = "pip_available" | ||
@JvmStatic | ||
|
@@ -130,7 +128,6 @@ abstract class BaseGodotEditor : GodotActivity() { | |
} | ||
|
||
private val editorMessageDispatcher = EditorMessageDispatcher(this) | ||
private val commandLineParams = ArrayList<String>() | ||
private val editorLoadingIndicator: View? by lazy { findViewById(R.id.editor_loading_indicator) } | ||
|
||
override fun getGodotAppLayout() = R.layout.godot_editor_layout | ||
|
@@ -183,10 +180,6 @@ abstract class BaseGodotEditor : GodotActivity() { | |
// requested on demand based on use cases. | ||
PermissionsUtil.requestManifestPermissions(this, getExcludedPermissions()) | ||
|
||
val params = intent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS) | ||
Log.d(TAG, "Starting intent $intent with parameters ${params.contentToString()}") | ||
updateCommandLineParams(params?.asList() ?: emptyList()) | ||
|
||
editorMessageDispatcher.parseStartIntent(packageManager, intent) | ||
|
||
if (BuildConfig.BUILD_TYPE == "dev" && WAIT_FOR_DEBUGGER) { | ||
|
@@ -219,20 +212,16 @@ abstract class BaseGodotEditor : GodotActivity() { | |
} | ||
|
||
@CallSuper | ||
protected open fun updateCommandLineParams(args: List<String>) { | ||
// Update the list of command line params with the new args | ||
commandLineParams.clear() | ||
if (args.isNotEmpty()) { | ||
commandLineParams.addAll(args) | ||
} | ||
if (BuildConfig.BUILD_TYPE == "dev") { | ||
commandLineParams.add("--benchmark") | ||
protected override fun updateCommandLineParams(args: Array<String>) { | ||
val args = if (BuildConfig.BUILD_TYPE == "dev") { | ||
args + "--benchmark" | ||
} else { | ||
args | ||
} | ||
super.updateCommandLineParams(args); | ||
} | ||
|
||
final override fun getCommandLine() = commandLineParams | ||
|
||
protected fun retrieveEditorWindowInfo(args: Array<String>): EditorWindowInfo { | ||
protected open fun retrieveEditorWindowInfo(args: Array<String>): EditorWindowInfo { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this change can be reverted |
||
var hasEditor = false | ||
var xrMode = XR_MODE_DEFAULT | ||
|
||
|
@@ -335,14 +324,7 @@ abstract class BaseGodotEditor : GodotActivity() { | |
val newInstance = getNewGodotInstanceIntent(editorWindowInfo, args) | ||
if (editorWindowInfo.windowClassName == javaClass.name) { | ||
Log.d(TAG, "Restarting ${editorWindowInfo.windowClassName} with parameters ${args.contentToString()}") | ||
val godot = godot | ||
if (godot != null) { | ||
godot.destroyAndKillProcess { | ||
ProcessPhoenix.triggerRebirth(this, activityOptions?.toBundle(), newInstance) | ||
} | ||
} else { | ||
ProcessPhoenix.triggerRebirth(this, activityOptions?.toBundle(), newInstance) | ||
} | ||
triggerRebirth(activityOptions?.toBundle(), newInstance) | ||
} else { | ||
Log.d(TAG, "Starting ${editorWindowInfo.windowClassName} with parameters ${args.contentToString()}") | ||
newInstance.putExtra(EXTRA_NEW_LAUNCH, true) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new variable should have a different name otherwise it shadows the function parameter, and may lead to subtle bugs / mistakes when this method is updated in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO that's a feature, not a bug.. if you have multiple variables around that's when you might choose the wrong variable
https://discuss.kotlinlang.org/t/rust-style-variable-shadowing/16338
if there's only one 'args' then you can't use the 'wrong' one. I want to 'destroy' the old 'args' value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a fair argument.. I don't have a preference one way or another but since it seems to match the use-case here, it can remain as is. Note though that this would not work in the
GodotXRGame
use-case since we're updating the arguments several times based on separate constraints.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to me to add a bunch of stuff to a list, then call
toTypedArray()
to pass it on in that case (which is howGodotXRGame.updateCommandLineParams()
works in this change)setCommandLineParams()
since it's only ever called once and always sets the entire array/list at once and each level only really calls it once to set it's arguments and then passes them to super().List<String>
and let each level add it's own args. The consumer could callpublic getCommandLine(): Array<String>
to get the result after the end.setCommandLineParams()
threw when it's too late then that would make sense though.