@@ -82,6 +82,26 @@ CameraView* FrameProcessorRuntimeManager::findCameraViewById(int viewId) {
82
82
return result->cthis ();
83
83
}
84
84
85
+ void FrameProcessorRuntimeManager::logErrorToJS (std::string message) {
86
+ if (!this ->jsCallInvoker_ ) {
87
+ return ;
88
+ }
89
+
90
+ this ->jsCallInvoker_ ->invokeAsync ([this , message]() {
91
+ if (this ->runtime_ == nullptr ) {
92
+ return ;
93
+ }
94
+
95
+ auto & runtime = *this ->runtime_ ;
96
+ auto consoleError = runtime
97
+ .global ()
98
+ .getPropertyAsObject (runtime, " console" )
99
+ .getPropertyAsFunction (runtime, " error" );
100
+ consoleError.call (runtime, jsi::String::createFromUtf8 (runtime, message));
101
+ });
102
+ }
103
+
104
+
85
105
// actual JSI installer
86
106
void FrameProcessorRuntimeManager::installJSIBindings () {
87
107
__android_log_write (ANDROID_LOG_INFO, TAG, " Installing JSI bindings..." );
@@ -132,10 +152,16 @@ void FrameProcessorRuntimeManager::installJSIBindings() {
132
152
auto function = std::make_shared<jsi::Function>(worklet->getValue (rt).asObject (rt).asFunction (rt));
133
153
134
154
// assign lambda to frame processor
135
- cameraView->setFrameProcessor ([&rt, function](jni::local_ref<JImageProxy::javaobject> frame) {
136
- // create HostObject which holds the Frame (JImageProxy)
137
- auto hostObject = std::make_shared<JImageProxyHostObject>(frame);
138
- function->call (rt, jsi::Object::createFromHostObject (rt, hostObject));
155
+ cameraView->setFrameProcessor ([this , &rt, function](jni::local_ref<JImageProxy::javaobject> frame) {
156
+ try {
157
+ // create HostObject which holds the Frame (JImageProxy)
158
+ auto hostObject = std::make_shared<JImageProxyHostObject>(frame);
159
+ function->call (rt, jsi::Object::createFromHostObject (rt, hostObject));
160
+ } catch (jsi::JSError& jsError) {
161
+ auto message = " Frame Processor threw an error: " + jsError.getMessage ();
162
+ __android_log_write (ANDROID_LOG_ERROR, TAG, message.c_str ());
163
+ this ->logErrorToJS (message);
164
+ }
139
165
});
140
166
141
167
__android_log_write (ANDROID_LOG_INFO, TAG, " Frame Processor set!" );
0 commit comments