Mid-frame view flushing can deadlock when the render thread synchronously waits for JavaScript

Open
#1,904 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@bkaradzic-microsoft is already working on this.

Since Sep 30, 2026.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, javascript

Research direction

Start in Core/Graphics/Source/DeviceImpl.cpp at upstream commit 3450373508, tracing FlushViewsIfNeeded(), PerformMidFrameViewFlush(), and FinishRenderingCurrentFrame(). Exercise the triggering sequence around the maxViews - 16 threshold and confirm the circular wait or establish the required host-side frame-pumping contract. Done means the flush no longer hangs, or unsupported synchronous dispatch fails explicitly and its contract is documented and enforced.

Written by the indexing model from the issue text.

Description

Summary

DeviceImpl::FlushViewsIfNeeded() can wait indefinitely when an embedding application synchronously waits for JavaScript rendering to finish before calling FinishRenderingCurrentFrame().

The current guard checks that at least one frame-completion scope is active, but an active scope does not establish that the render thread is available to service a mid-frame flush.

Triggering sequence
  1. The render thread dispatches rendering work to the JS thread and synchronously waits for it to complete, intending to finish the native frame afterward.
  2. With a frame-completion scope active, JS submits enough render-target passes to reach the mid-frame view-flush threshold (maxViews - 16).
  3. FlushViewsIfNeeded() sets m_flushRequested and waits on m_flushCompleteCV.
  4. The render thread cannot reach FinishRenderingCurrentFrame() to service that request until JS returns. JS cannot return until the flush completes.

This creates a circular wait:

Render thread: waiting for JS rendering to complete
JS thread:     waiting for render thread to service a view flush
Expected behavior

The flush should complete, or an unsupported frame-driving pattern should fail explicitly rather than hang. If synchronous dispatch is unsupported, the required host-side frame-pumping contract should be documented and enforced.

Evidence and scope

A repeatable rendering stall was observed when the workload crossed the flush threshold. The circular-wait explanation is based on source inspection; a debugger-confirmed pair of blocked thread stacks and a standalone public reproducer are not yet available.

The relevant implementation is DeviceImpl.cpp at upstream commit 3450373508, particularly FlushViewsIfNeeded(), PerformMidFrameViewFlush(), and FinishRenderingCurrentFrame().

Increasing the view capacity avoids this path for workloads that remain below the new threshold, but does not fix the underlying synchronization dependency.

Dominant language
C++
Stars
931
Forks
169
Avg merge
2d 17h
Merged PRs (30d)
66

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from BabylonJS/BabylonNative

All issues in BabylonJS/BabylonNative

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.