backend: Propagate backend thread exceptions to the main thread. (#9903)
* Filament Error Handling Remediation and noexcept Cleanup - Replaced assert_invariant with FILAMENT_CHECK_PRECONDITION in Renderer::beginFrame for caller bugs. - Removed noexcept from Camera::setCustomProjection to allow precondition checks to throw. - Removed noexcept from Texture and InstanceBuffer methods using precondition checks. - Documented silent clamping in View::setBloomOptions. - Clarified comment in FrameGraphResources regarding preconditions. - Refined MaterialInstance::commit to split texture loop into check and update passes, preventing partial state changes on precondition failure. * backend: Propagate backend thread exceptions to the main thread. Introduce a mechanism to catch exceptions thrown on the backend thread and rethrow them on the main thread. This prevents deadlocks and allows the application to handle fatal backend failures gracefully. - Consolidate synchronization primitives in DriverBase. - Add mHasUnrecoverableError flag to interrupt blocked fence waits. - Optimize waitForFence to avoid extra atomic reads in common paths. - Propagate FenceStatus::ERROR across all backends. - CommandBufferQueue now stores a std::exception_ptr when the backend fails. - The backend enters a "zombie" state on failure, skipping further command execution but allowing clean shutdown. - Public APIs in Renderer and Engine now check for stored exceptions and rethrow them, documented with @throws. - Guarded by __EXCEPTIONS to ensure no overhead when exceptions are disabled. - Add unit test for fence interruption and document new APIs. BUGS=[407545700] * feat: harden backend exceptions and add hasUnrecoverableFailure API - Update Renderer::beginFrame() and Renderer::shouldRenderFrame() to return false early if an unrecoverable backend exception has been delivered to the main thread. - Document the new return behavior for beginFrame() and shouldRenderFrame() in Renderer.h. - Add Engine::hasUnrecoverableFailure() to the public API to allow apps to check for fatal errors without relying on exceptions. - Implement hasUnrecoverableFailure() in FEngine by delegating to CommandBufferQueue. - Expose Engine::hasUnrecoverableFailure() to Java bindings (Engine.java and JNI). - Expose Engine::hasUnrecoverableFailure() to JavaScript bindings (jsbindings.cpp). * java: propagate C++ Panics & exceptions to JAVA
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <functional>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -24,6 +23,7 @@
|
||||
|
||||
#include "common/CallbackUtils.h"
|
||||
#include "common/NioUtils.h"
|
||||
#include <common/JniUtils.h>
|
||||
|
||||
using namespace filament;
|
||||
using namespace backend;
|
||||
@@ -60,11 +60,13 @@ Java_com_google_android_filament_SkinningBuffer_nBuilderInitialize(JNIEnv*, jcla
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_google_android_filament_SkinningBuffer_nBuilderBuild(JNIEnv*, jclass,
|
||||
Java_com_google_android_filament_SkinningBuffer_nBuilderBuild(JNIEnv* env, jclass,
|
||||
jlong nativeBuilder, jlong nativeEngine) {
|
||||
SkinningBuffer::Builder* builder = (SkinningBuffer::Builder *) nativeBuilder;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
return (jlong) builder->build(*engine);
|
||||
return filament::android::wrapJni<jlong>(env, [=]() {
|
||||
return (jlong) builder->build(*engine);
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -76,16 +78,18 @@ Java_com_google_android_filament_SkinningBuffer_nSetBonesAsMatrices(JNIEnv* env,
|
||||
jint offset) {
|
||||
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
AutoBuffer nioBuffer(env, matrices, boneCount * 16);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
skinningBuffer->setBones(*engine,
|
||||
static_cast<filament::math::mat4f const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
return filament::android::wrapJni<jint>(env, [=]() {
|
||||
AutoBuffer nioBuffer(env, matrices, boneCount * 16);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
skinningBuffer->setBones(*engine,
|
||||
static_cast<filament::math::mat4f const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -95,16 +99,18 @@ Java_com_google_android_filament_SkinningBuffer_nSetBonesAsQuaternions(JNIEnv* e
|
||||
jint boneCount, jint offset) {
|
||||
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
|
||||
Engine *engine = (Engine *) nativeEngine;
|
||||
AutoBuffer nioBuffer(env, quaternions, boneCount * 8);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
skinningBuffer->setBones(*engine,
|
||||
static_cast<RenderableManager::Bone const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
return filament::android::wrapJni<jint>(env, [=]() {
|
||||
AutoBuffer nioBuffer(env, quaternions, boneCount * 8);
|
||||
void* data = nioBuffer.getData();
|
||||
size_t sizeInBytes = nioBuffer.getSize();
|
||||
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
|
||||
// BufferOverflowException
|
||||
return -1;
|
||||
}
|
||||
skinningBuffer->setBones(*engine,
|
||||
static_cast<RenderableManager::Bone const *>(data), (size_t)boneCount, (size_t)offset);
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
||||
Reference in New Issue
Block a user