File tree 2 files changed +12
-6
lines changed
2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -41,8 +41,7 @@ class RNSkPlatformContext {
41
41
std::shared_ptr<react::CallInvoker> callInvoker,
42
42
float pixelDensity)
43
43
: _pixelDensity(pixelDensity), _jsRuntime(runtime),
44
- _callInvoker (callInvoker) {
45
- }
44
+ _callInvoker (callInvoker) {}
46
45
47
46
virtual ~RNSkPlatformContext () = default ;
48
47
Original file line number Diff line number Diff line change @@ -173,10 +173,17 @@ class RNSkView : public std::enable_shared_from_this<RNSkView> {
173
173
void requestRedraw () {
174
174
if (!_redrawRequested) {
175
175
_redrawRequested = true ;
176
- _platformContext->runOnMainThread ([this ]() {
177
- if (_renderer) {
178
- _renderer->renderImmediate (_canvasProvider);
179
- _redrawRequested = false ;
176
+ // Capture a weak pointer to this
177
+ auto weakThis = std::weak_ptr<RNSkView>(shared_from_this ());
178
+
179
+ _platformContext->runOnMainThread ([weakThis]() {
180
+ // Try to lock the weak pointer
181
+ if (auto strongThis = weakThis.lock ()) {
182
+ // Only proceed if the object still exists
183
+ if (strongThis->_renderer ) {
184
+ strongThis->_renderer ->renderImmediate (strongThis->_canvasProvider );
185
+ strongThis->_redrawRequested = false ;
186
+ }
180
187
}
181
188
});
182
189
}
You can’t perform that action at this time.
0 commit comments