Skip to content

Commit 0ae6cf4

Browse files
committed
Fix build issues from merge
1 parent bdaf1b9 commit 0ae6cf4

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

Core/Graphics/Source/DeviceImpl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,16 @@ namespace Babylon::Graphics
300300
return m_afterRenderDispatcher.scheduler();
301301
}
302302

303-
void DeviceImpl::RequestScreenShot(std::function<void(std::vector<uint8_t>)> callback)
303+
arcana::task<std::vector<uint8_t>, std::exception_ptr> DeviceImpl::RequestScreenShotAsync()
304304
{
305-
m_screenShotCallbacks.push(std::move(callback));
305+
arcana::task_completion_source<std::vector<uint8_t>, std::exception_ptr> taskCompletionSource{};
306+
307+
m_screenShotCallbacks.push([taskCompletionSource](std::vector<uint8_t> bytes) mutable
308+
{
309+
taskCompletionSource.complete(std::move(bytes));
310+
});
311+
312+
return taskCompletionSource.as_task();
306313
}
307314

308315
arcana::task<void, std::exception_ptr> DeviceImpl::ReadTextureAsync(bgfx::TextureHandle handle, gsl::span<uint8_t> data, uint8_t mipLevel)

Core/Graphics/Source/DeviceImpl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ namespace Babylon::Graphics
7878
continuation_scheduler<>& BeforeRenderScheduler();
7979
continuation_scheduler<>& AfterRenderScheduler();
8080

81-
Update GetUpdate(const char* updateName);
82-
8381
arcana::task<std::vector<uint8_t>, std::exception_ptr> RequestScreenShotAsync();
8482

8583
arcana::task<void, std::exception_ptr> ReadTextureAsync(bgfx::TextureHandle handle, gsl::span<uint8_t> data, uint8_t mipLevel);

Plugins/NativeCamera/Source/MediaStream.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Babylon::Plugins
1616
auto mediaStreamObject{Napi::Persistent(GetConstructor(env).New({}))};
1717
auto mediaStream{MediaStream::Unwrap(mediaStreamObject.Value())};
1818

19-
return mediaStream->ApplyInitialConstraintsAsync(constraints).then(mediaStream->m_runtimeScheduler, arcana::cancellation::none(), [mediaStreamObject{std::move(mediaStreamObject)}]() {
19+
return mediaStream->ApplyInitialConstraintsAsync(constraints).then(arcana::inline_scheduler, arcana::cancellation::none(), [mediaStreamObject{std::move(mediaStreamObject)}]() {
2020
return mediaStreamObject.Value();
2121
});
2222
}
@@ -58,14 +58,18 @@ namespace Babylon::Plugins
5858

5959
MediaStream::~MediaStream()
6060
{
61-
// TODO: Is this still necessary?
62-
// if (m_cameraDevice != nullptr)
63-
// {
64-
// // The cameraDevice should be destroyed on the JS thread as it may need to access main thread resources
65-
// // move ownership of the cameraDevice to a lambda and dispatch it with the runtimeScheduler so the destructor
66-
// // is called from that thread.
67-
// m_runtimeScheduler.Get()([cameraDevice = std::move(m_cameraDevice)]() {});
68-
// }
61+
m_cancellationSource.cancel();
62+
63+
// HACK: This is a hack to make sure the camera device is destroyed on the JS thread.
64+
// The napi-jsi adapter currently calls the destructors of JS objects possibly on the wrong thread.
65+
// Once this is fixed, this hack will no longer be needed.
66+
if (m_cameraDevice != nullptr)
67+
{
68+
// The cameraDevice should be destroyed on the JS thread as it may need to access main thread resources
69+
// move ownership of the cameraDevice to a lambda and dispatch it with the runtimeScheduler so the destructor
70+
// is called from that thread.
71+
m_runtimeScheduler.Get()([cameraDevice = std::move(m_cameraDevice)]() {});
72+
}
6973

7074
// Wait for async operations to complete.
7175
m_runtimeScheduler.Rundown();
@@ -124,7 +128,7 @@ namespace Babylon::Plugins
124128
// Create a persistent ref to the constraints object so it isn't destructed during our async work
125129
auto constraintsRef{Napi::Persistent(constraints)};
126130

127-
return m_cameraDevice->OpenAsync(bestCamera.value().second).then(m_runtimeScheduler.Get(), arcana::cancellation::none(), [this, constraintsRef{std::move(constraintsRef)}](CameraDevice::CameraDimensions cameraDimensions) {
131+
return m_cameraDevice->OpenAsync(bestCamera.value().second).then(m_runtimeScheduler.Get(), m_cancellationSource, [this, constraintsRef{std::move(constraintsRef)}](CameraDevice::CameraDimensions cameraDimensions) {
128132
this->Width = cameraDimensions.width;
129133
this->Height = cameraDimensions.height;
130134

Plugins/NativeCamera/Source/MediaStream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace Babylon::Plugins
4646
// Capture CameraDevice in a shared_ptr because the iOS implementation relies on the `shared_from_this` syntax for async work
4747
std::shared_ptr<CameraDevice> m_cameraDevice{};
4848
JsRuntimeScheduler m_runtimeScheduler;
49+
arcana::cancellation_source m_cancellationSource;
4950

5051
Napi::ObjectReference m_currentConstraints{};
5152
};

0 commit comments

Comments
 (0)