[Android] Fix dynamic Variant params stack constructions in JNI callbacks #76640
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.
Emitting signals with params from Android plugins could crash due to object assignment with uninitialised mem.
Instead, use memnew_placement to construct into stack addresses.
This appears to be introduced in godot 4.0 from refactoring so not applicable for 3.x.
Java_org_godotengine_godot_plugin_GodotPlugin_nativeEmitSignal was main issue and whilst appeared to run fine with Armv8 ABI for me, consistently crashed when running Armv7.
Java_org_godotengine_godot_GodotLib_callobject was not affected due to constructing a nil Variant to the stack addresses before assignment.
Java_org_godotengine_godot_GodotLib_calldeferred looked to have same issue but not sure if actually used.
I've updated the above three calls for consistency.
Not sure the circumstances that GetObjectArrayElement could return null (out of java refs/mem?) but was being tested in some funcs. I've changed to an ERR_FAIL_NULL as I believe it better to abort the call than continue with partially converted params.
JNI Push/PopLocalFrame calls have been removed from call funcs as seem somewhat redundant here and could interfere with early return. May reduce local java refs capacity by a couple.
Fixes #75754.
Probably Fixes #69297.
Thanks to @Ajrarn777 for assistance in tracking this down.