From 6fbf8a8be0f652bf87c2729a546431fdda0406c8 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Tue, 28 Jan 2020 12:53:23 -0800 Subject: [PATCH] Fix event pumping with non-owned platforms. Tested with WebGL and macOS. --- filament/src/Engine.cpp | 13 +++---------- filament/src/details/Engine.h | 4 ++++ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/filament/src/Engine.cpp b/filament/src/Engine.cpp index 233584e815..59bb0b07e5 100644 --- a/filament/src/Engine.cpp +++ b/filament/src/Engine.cpp @@ -109,8 +109,6 @@ FEngine* FEngine::create(Backend backend, Platform* platform, void* sharedGLCont // Normally we launch a thread and create the context and Driver from there (see FEngine::loop). // In the single-threaded case, we do so in the here and now. if (!UTILS_HAS_THREADING) { - // we don't own the external context at that point, set it to null - instance->mPlatform = nullptr; if (platform == nullptr) { platform = DefaultPlatform::create(&instance->mBackend); instance->mPlatform = platform; @@ -406,13 +404,8 @@ void FEngine::flushAndWait() { // ----------------------------------------------------------------------------------------------- int FEngine::loop() { - // we don't own the external context at that point, set it to null - Platform* platform = mPlatform; - mPlatform = nullptr; - - if (platform == nullptr) { - platform = DefaultPlatform::create(&mBackend); - mPlatform = platform; + if (mPlatform == nullptr) { + mPlatform = DefaultPlatform::create(&mBackend); mOwnPlatform = true; slog.d << "FEngine resolved backend: "; switch (mBackend) { @@ -460,7 +453,7 @@ int FEngine::loop() { JobSystem::setThreadName("FEngine::loop"); JobSystem::setThreadPriority(JobSystem::Priority::DISPLAY); - mDriver = platform->createDriver(mSharedGLContext); + mDriver = mPlatform->createDriver(mSharedGLContext); mDriverBarrier.latch(); if (UTILS_UNLIKELY(!mDriver)) { // if we get here, it's because the driver couldn't be initialized and the problem has diff --git a/filament/src/details/Engine.h b/filament/src/details/Engine.h index 38163cd7f5..25d082a385 100644 --- a/filament/src/details/Engine.h +++ b/filament/src/details/Engine.h @@ -268,6 +268,10 @@ public: // flush the current buffer void flush(); + /** + * Processes the platform's event queue when called from the platform's event-handling thread. + * Returns false when called from any other thread. + */ bool pumpPlatformEvents() { return mPlatform->pumpEvents(); }