You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Android: Stabilize camera lifecycle handling
- Pause camera feeds during lifecycle transitions to avoid crashes - Refresh camera metadata after rotation to keep orientation accurate
This commit is contained in:
@@ -52,6 +52,13 @@
|
||||
#include "main/main.h"
|
||||
#include "servers/rendering/rendering_server.h"
|
||||
|
||||
#include "modules/modules_enabled.gen.h" // For camera.
|
||||
|
||||
#ifdef MODULE_CAMERA_ENABLED
|
||||
#include "modules/camera/camera_android.h"
|
||||
#include "servers/camera/camera_server.h"
|
||||
#endif
|
||||
|
||||
#ifndef XR_DISABLED
|
||||
#include "servers/xr/xr_server.h"
|
||||
#endif // XR_DISABLED
|
||||
@@ -593,6 +600,12 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNI
|
||||
|
||||
// We force redraw to ensure we render at least once when resuming the app.
|
||||
Main::force_redraw();
|
||||
#ifdef MODULE_CAMERA_ENABLED
|
||||
CameraAndroid *camera_android = Object::cast_to<CameraAndroid>(CameraServer::get_singleton());
|
||||
if (camera_android) {
|
||||
camera_android->handle_resume();
|
||||
}
|
||||
#endif // MODULE_CAMERA_ENABLED
|
||||
if (os_android->get_main_loop()) {
|
||||
os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_RESUMED);
|
||||
}
|
||||
@@ -603,11 +616,31 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused(JNIE
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef MODULE_CAMERA_ENABLED
|
||||
CameraAndroid *camera_android = Object::cast_to<CameraAndroid>(CameraServer::get_singleton());
|
||||
if (camera_android) {
|
||||
camera_android->handle_pause();
|
||||
}
|
||||
#endif // MODULE_CAMERA_ENABLED
|
||||
|
||||
if (os_android->get_main_loop()) {
|
||||
os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_PAUSED);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onScreenRotationChange(JNIEnv *env, jclass clazz) {
|
||||
if (step.get() <= STEP_SETUP) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef MODULE_CAMERA_ENABLED
|
||||
CameraAndroid *camera_android = Object::cast_to<CameraAndroid>(CameraServer::get_singleton());
|
||||
if (camera_android) {
|
||||
camera_android->handle_rotation_change();
|
||||
}
|
||||
#endif // MODULE_CAMERA_ENABLED
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_shouldDispatchInputToRenderThread(JNIEnv *env, jclass clazz) {
|
||||
Input *input = Input::get_singleton();
|
||||
if (input) {
|
||||
|
||||
Reference in New Issue
Block a user