Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Fix issue with JNI Env not available for audio (#182)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #182

The Hermes GC will eventually clean up orphan host objects. This is also the case for `AudioHostObject`, which itself has a reference to `Audio` that needs to be cleaned up, hence the call to the `Audio::~Audio` destructor. On Android, it will try to release the `global_ref<JAudio>` resource, which at the time, may not run in the JVM thread scope causing an app crash.

Reviewed By: ansonsyfang

Differential Revision: D42060942

fbshipit-source-id: b19f723f361db3794b704be97456bd4bbe980848
  • Loading branch information
raedle committed Dec 17, 2022
1 parent 0723cc0 commit c0b2026
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ Audio::Audio(alias_ref<JIAudio> audio) : audio_(make_global(audio)) {
id_ = wrapObjectMethod(mediaUtilsClass, audio)->toStdString();
}

Audio::~Audio() {
ThreadScope::WithClassLoader([&]() {
Environment::ensureCurrentThreadIsAttached();
this->audio_.release();
});
}

std::string Audio::getId() const {
return id_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace media {
class Audio : public IAudio {
public:
Audio(facebook::jni::alias_ref<JIAudio> audio);
~Audio() override = default;
~Audio() override;

std::string getId() const override;

Expand Down

0 comments on commit c0b2026

Please sign in to comment.