diff --git a/packages/skia/cpp/rnskia/RNSkPlatformContext.h b/packages/skia/cpp/rnskia/RNSkPlatformContext.h index e64d6deef0..8303d327e0 100644 --- a/packages/skia/cpp/rnskia/RNSkPlatformContext.h +++ b/packages/skia/cpp/rnskia/RNSkPlatformContext.h @@ -41,8 +41,7 @@ class RNSkPlatformContext { std::shared_ptr callInvoker, float pixelDensity) : _pixelDensity(pixelDensity), _jsRuntime(runtime), - _callInvoker(callInvoker) { - } + _callInvoker(callInvoker) {} virtual ~RNSkPlatformContext() = default; diff --git a/packages/skia/cpp/rnskia/RNSkView.h b/packages/skia/cpp/rnskia/RNSkView.h index 85c30ec4f2..3c7f2ee451 100644 --- a/packages/skia/cpp/rnskia/RNSkView.h +++ b/packages/skia/cpp/rnskia/RNSkView.h @@ -173,10 +173,17 @@ class RNSkView : public std::enable_shared_from_this { void requestRedraw() { if (!_redrawRequested) { _redrawRequested = true; - _platformContext->runOnMainThread([this]() { - if (_renderer) { - _renderer->renderImmediate(_canvasProvider); - _redrawRequested = false; + // Capture a weak pointer to this + auto weakThis = std::weak_ptr(shared_from_this()); + + _platformContext->runOnMainThread([weakThis]() { + // Try to lock the weak pointer + if (auto strongThis = weakThis.lock()) { + // Only proceed if the object still exists + if (strongThis->_renderer) { + strongThis->_renderer->renderImmediate(strongThis->_canvasProvider); + strongThis->_redrawRequested = false; + } } }); }