Skip to content

Commit

Permalink
fix: fix cleanup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed May 14, 2024
1 parent 6cf905b commit 7e6cd51
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
17 changes: 11 additions & 6 deletions package/cpp/ChoreographerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

namespace margelo {

ChoreographerWrapper::~ChoreographerWrapper() {
if (!isRuntimeAlive()) {
// This will not delete the underlying pointer.
// When the runtime is destroyed we can't call the jsi::Value's destructor,
// as we would run into a crash (as the runtime is already gone).
_renderCallback.release();
}
}

void ChoreographerWrapper::loadHybridMethods() {
registerHybridMethod("start", &ChoreographerWrapper::start, this);
registerHybridMethod("stop", &ChoreographerWrapper::stop, this);
Expand Down Expand Up @@ -75,7 +84,6 @@ void ChoreographerWrapper::cleanup() {
Logger::log(TAG, "Cleanup ChoreographerWrapper");

_renderCallback = nullptr;
Logger::log(TAG, "Runtime active, cleaning callback...");

// Its possible that the pointer was already released manually by the user
if (getIsValid()) {
Expand All @@ -95,16 +103,13 @@ void ChoreographerWrapper::release() {

void ChoreographerWrapper::onRuntimeDestroyed(jsi::Runtime*) {
std::unique_lock lock(_mutex);
Logger::log(TAG, "Runtime destroyed, stopping choreographer...");

if (getIsValid()) {
Logger::log(TAG, "Runtime destroyed, stopping choreographer...");
pointee()->stop();
}

// This will not delete the underlying pointer.
// When the runtime is destroyed we can't call the jsi::Value's destructor,
// as we would run into a crash (as the runtime is already gone).
_renderCallback.release();
_renderCallback = nullptr;
}

std::shared_ptr<Choreographer> ChoreographerWrapper::getChoreographer() {
Expand Down
1 change: 1 addition & 0 deletions package/cpp/ChoreographerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using RenderCallback = std::function<void(FrameInfo)>;
class ChoreographerWrapper : public PointerHolder<Choreographer>, public RuntimeLifecycleListener {
public:
explicit ChoreographerWrapper(std::shared_ptr<Choreographer> choreographer) : PointerHolder(TAG, choreographer) {}
~ChoreographerWrapper() override;

void loadHybridMethods() override;

Expand Down
44 changes: 22 additions & 22 deletions package/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -886,81 +886,81 @@ PODS:
- React-Mapbuffer (0.73.4):
- glog
- React-debug
- react-native-filament (0.35.0):
- react-native-filament (0.35.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/camutils (= 0.35.0)
- react-native-filament/filamat (= 0.35.0)
- react-native-filament/filament (= 0.35.0)
- react-native-filament/gltfio_core (= 0.35.0)
- react-native-filament/image (= 0.35.0)
- react-native-filament/ktxreader (= 0.35.0)
- react-native-filament/math (= 0.35.0)
- react-native-filament/tsl (= 0.35.0)
- react-native-filament/uberz (= 0.35.0)
- react-native-filament/utils (= 0.35.0)
- react-native-filament/camutils (= 0.35.2)
- react-native-filament/filamat (= 0.35.2)
- react-native-filament/filament (= 0.35.2)
- react-native-filament/gltfio_core (= 0.35.2)
- react-native-filament/image (= 0.35.2)
- react-native-filament/ktxreader (= 0.35.2)
- react-native-filament/math (= 0.35.2)
- react-native-filament/tsl (= 0.35.2)
- react-native-filament/uberz (= 0.35.2)
- react-native-filament/utils (= 0.35.2)
- react-native-worklets-core
- react-native-filament/camutils (0.35.0):
- react-native-filament/camutils (0.35.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/math
- react-native-worklets-core
- react-native-filament/filamat (0.35.0):
- react-native-filament/filamat (0.35.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/math
- react-native-filament/utils
- react-native-worklets-core
- react-native-filament/filament (0.35.0):
- react-native-filament/filament (0.35.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/math
- react-native-filament/utils
- react-native-worklets-core
- react-native-filament/gltfio_core (0.35.0):
- react-native-filament/gltfio_core (0.35.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/filament
- react-native-filament/ktxreader
- react-native-filament/uberz
- react-native-worklets-core
- react-native-filament/image (0.35.0):
- react-native-filament/image (0.35.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/filament
- react-native-worklets-core
- react-native-filament/ktxreader (0.35.0):
- react-native-filament/ktxreader (0.35.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/filament
- react-native-filament/image
- react-native-worklets-core
- react-native-filament/math (0.35.0):
- react-native-filament/math (0.35.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-worklets-core
- react-native-filament/tsl (0.35.0):
- react-native-filament/tsl (0.35.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-worklets-core
- react-native-filament/uberz (0.35.0):
- react-native-filament/uberz (0.35.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/filamat
- react-native-filament/tsl
- react-native-filament/utils
- react-native-worklets-core
- react-native-filament/utils (0.35.0):
- react-native-filament/utils (0.35.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
Expand Down Expand Up @@ -1358,7 +1358,7 @@ SPEC CHECKSUMS:
React-jsinspector: 9ac353eccf6ab54d1e0a33862ba91221d1e88460
React-logger: 0a57b68dd2aec7ff738195f081f0520724b35dab
React-Mapbuffer: 63913773ed7f96b814a2521e13e6d010282096ad
react-native-filament: 8e5ee44c0cd5ceac3b4c189aa71e9d180cb13d27
react-native-filament: 9550e77b63b9f67b58c46c57406b74b92c363857
react-native-safe-area-context: b97eb6f9e3b7f437806c2ce5983f479f8eb5de4b
react-native-video: b2bb32d1453ab276ca03044f5c93b2e4cdb52019
react-native-worklets-core: ff4a4076ad86469e61ec8e39da2cb13c55da2385
Expand Down

0 comments on commit 7e6cd51

Please sign in to comment.