Skip to content

Commit 54494eb

Browse files
committed
Fix a crash for IBL resource loading
This fixes a crash introduced by a8ace28 The refactored FrameInfoManager is now required to be called properly within the renderStandaloneView method, which is mainly being called by IBLPrefilterContext. Also fix a null pointer reference bug for OpenGLTimer::State, which happenes when the renderer for IBLPrefilterContext is destroyed.
1 parent b54a204 commit 54494eb

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

filament/backend/src/opengl/OpenGLTimerQuery.cpp

+18-14
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,25 @@ void TimerQueryNativeFactory::endTimeElapsedQuery(OpenGLDriver& driver, GLTimerQ
143143

144144
driver.runEveryNowAndThen([&context = mContext, weak]() -> bool {
145145
auto state = weak.lock();
146-
if (state) {
147-
GLuint available = 0;
148-
context.procs.getQueryObjectuiv(state->gl.query, GL_QUERY_RESULT_AVAILABLE, &available);
149-
CHECK_GL_ERROR(utils::slog.e)
150-
if (!available) {
151-
// we need to try this one again later
152-
return false;
153-
}
154-
GLuint64 elapsedTime = 0;
155-
// we won't end-up here if we're on ES and don't have GL_EXT_disjoint_timer_query
156-
context.procs.getQueryObjectui64v(state->gl.query, GL_QUERY_RESULT, &elapsedTime);
157-
state->elapsed.store((int64_t)elapsedTime, std::memory_order_relaxed);
158-
} else {
159-
state->elapsed.store(int64_t(TimerQueryResult::ERROR), std::memory_order_relaxed);
146+
if (!state) {
147+
// The timer query state has been destroyed on the way, very likely due to the IBL
148+
// prefilter context destruction. We still return true to get this element removed from
149+
// the query list.
150+
return true;
160151
}
152+
153+
GLuint available = 0;
154+
context.procs.getQueryObjectuiv(state->gl.query, GL_QUERY_RESULT_AVAILABLE, &available);
155+
CHECK_GL_ERROR(utils::slog.e)
156+
if (!available) {
157+
// we need to try this one again later
158+
return false;
159+
}
160+
GLuint64 elapsedTime = 0;
161+
// we won't end-up here if we're on ES and don't have GL_EXT_disjoint_timer_query
162+
context.procs.getQueryObjectui64v(state->gl.query, GL_QUERY_RESULT, &elapsedTime);
163+
state->elapsed.store((int64_t)elapsedTime, std::memory_order_relaxed);
164+
161165
return true;
162166
});
163167
}

filament/src/details/Renderer.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,16 @@ void FRenderer::renderStandaloneView(FView const* view) {
525525
1'000'000'000.0 / mDisplayInfo.refreshRate),
526526
mFrameId);
527527

528+
// This need to occur after the backend beginFrame() because some backends need to start
529+
// a command buffer before creating a fence.
530+
mFrameInfoManager.beginFrame(driver, {
531+
.historySize = mFrameRateOptions.history
532+
}, mFrameId);
533+
528534
renderInternal(view);
529535

536+
mFrameInfoManager.endFrame(driver);
537+
530538
driver.endFrame(mFrameId);
531539
}
532540
}

0 commit comments

Comments
 (0)