Skip to content

Commit 79d65a7

Browse files
authored
Fix(FrameInfo): fix typos and endFrame logic (#9499)
When the frame history's circular queue is full and the oldest frame is not yet ready to be processed, we must skip the current frame. This change ensures that if `beginFrame` is skipped, the corresponding `endFrame` is also skipped. This prevents data corruption in the frame history.
1 parent 37610dc commit 79d65a7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

filament/src/FrameInfo.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ void FrameInfoManager::beginFrame(FSwapChain* swapChain, DriverApi& driver,
114114
// front element of the queue, we can't pop/push. Our only option is to not record
115115
// a new entry for this frame, which will create a false skipped frame in the
116116
// data.
117-
LOG(WARNING) << "FrameInfo's circular queue is full, but the latest item hasn't "
118-
" been processed yet. Skipping this frame, id = " << frameId;
117+
LOG(WARNING) << "FrameInfo's circular queue is full, but the oldest item hasn't "
118+
"been processed yet. Skipping this frame, id = " << frameId;
119+
mLastBeginFrameSkipped = true;
120+
return;
119121
}
120122
}
121123

@@ -204,6 +206,14 @@ void FrameInfoManager::beginFrame(FSwapChain* swapChain, DriverApi& driver,
204206
}
205207

206208
void FrameInfoManager::endFrame(DriverApi& driver) noexcept {
209+
if (mLastBeginFrameSkipped) {
210+
// if we had to skip the last beginFrame(), endFrame() needs to be skipped too
211+
// because history.front() now references the wrong frame.
212+
// It is guaranteed that if beginFrame() is called, endFrame() will be called too.
213+
mLastBeginFrameSkipped = false;
214+
return;
215+
}
216+
207217
auto& front = mFrameTimeHistory.front();
208218
front.endFrame = std::chrono::steady_clock::now();
209219

filament/src/FrameInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ class FrameInfoManager {
315315
FrameHistoryQueue mFrameTimeHistory{};
316316
utils::AsyncJobQueue mJobQueue;
317317
FSwapChain* mLastSeenSwapChain = nullptr;
318+
bool mLastBeginFrameSkipped = false;
318319
bool const mHasTimerQueries = false;
319320
bool const mDisableGpuFrameComplete = false;
320321
};

0 commit comments

Comments
 (0)