Android: Stabilize camera lifecycle handling#111871
Android: Stabilize camera lifecycle handling#111871Repiteo merged 1 commit intogodotengine:masterfrom
Conversation
modules/camera/camera_android.h
Outdated
|
|
||
| struct RotationResult { | ||
| int rotationAngle; | ||
| bool shouldMirror; |
There was a problem hiding this comment.
I simplified it by using std::optional instead of a struct.
|
|
||
| val newOrientation = newConfig.orientation | ||
| if (currentOrientation != -1 && currentOrientation != newOrientation) { | ||
| GodotLib.onScreenRotationChange() |
There was a problem hiding this comment.
This ensures the screen rotation change callback is invoked on the render thread, similar to the renderer paused / resumed callbacks.
| GodotLib.onScreenRotationChange() | |
| runOnRenderThread { | |
| GodotLib.onScreenRotationChange() | |
| } |
cffd798 to
289ed9b
Compare
|
Fixes compilation of camera handlers from 060d312. |
| */ | ||
| private var renderViewInitialized = false | ||
| private var primaryHost: GodotHost? = null | ||
| private var currentOrientation = -1 |
There was a problem hiding this comment.
Let's replace this with:
private var currentConfig = context.resources.configuration
| val newOrientation = newConfig.orientation | ||
| if (currentOrientation != -1 && currentOrientation != newOrientation) { | ||
| runOnRenderThread { | ||
| GodotLib.onScreenRotationChange() | ||
| } | ||
| } | ||
| currentOrientation = newOrientation |
There was a problem hiding this comment.
| val newOrientation = newConfig.orientation | |
| if (currentOrientation != -1 && currentOrientation != newOrientation) { | |
| runOnRenderThread { | |
| GodotLib.onScreenRotationChange() | |
| } | |
| } | |
| currentOrientation = newOrientation | |
| if (currentConfig != null && currentConfig.orientation != newConfig.orientation) { | |
| runOnRenderThread { | |
| GodotLib.onScreenRotationChange() | |
| } | |
| } | |
| currentConfig = newConfig |
289ed9b to
a550b6f
Compare
| } | ||
|
|
||
| #ifdef MODULE_CAMERA_ENABLED | ||
| JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onScreenRotationChange(JNIEnv *env, jclass clazz) { |
There was a problem hiding this comment.
The method should be outside of the #ifdef, and be declared in java_godot_lib_jni.h like the other jni methods.
| /** | ||
| * Invoked when the screen orientation changes. | ||
| */ | ||
| public static native void onScreenRotationChange(); |
There was a problem hiding this comment.
| public static native void onScreenRotationChange(); | |
| static native void onScreenRotationChange(); |
m4gr3d
left a comment
There was a problem hiding this comment.
Looks good!
Can you squash the commits, and take care of that last comment.
ad5623b to
d3b5248
Compare
d3b5248 to
1ff3303
Compare
- Pause camera feeds during lifecycle transitions to avoid crashes - Refresh camera metadata after rotation to keep orientation accurate
1ff3303 to
4483871
Compare
|
I have applied the reviews up to this point. |
|
Thanks! |
Split from #110720
GodotLib.onScreenRotationChange()and guard image callbacks with a mutex to keep metadata refresh and frame delivery synchronized.I wanted to split the rotation handling and lifecycle event handling, but both rely on refresh_camera_metadata(), so I couldn’t separate them.
This PR provides the following benefits: