Skip to content

fix(core): preserve instance buffer during resource gc#3065

Open
sun-nocat wants to merge 2 commits into
dev/2.0from
xingyi/fix-instance-buffer-gc
Open

fix(core): preserve instance buffer during resource gc#3065
sun-nocat wants to merge 2 commits into
dev/2.0from
xingyi/fix-instance-buffer-gc

Conversation

@sun-nocat

@sun-nocat sun-nocat commented Jul 12, 2026

Copy link
Copy Markdown

Summary

  • keep the render pipeline's engine-owned instance buffer alive during ordinary resource-manager garbage collection
  • preserve explicit buffer destruction through BatcherManager.destroy() and engine teardown
  • add a focused Chromium regression test for both lifetime guarantees

Root cause

InstanceBuffer retained its GPU Buffer through a plain engine-owned field, so it had no component reference count. Because the buffer was not excluded from ordinary resource GC, ResourceManager.gc() could destroy it while the render pipeline still held and reused the wrapper. The next upload then reached a destroyed GLBuffer, causing repeated bindBuffer failures and WebGL context loss.

Validation

  • HEADLESS=true pnpm exec vitest run tests/src/core/RenderPipeline/InstanceBuffer.test.ts
  • pnpm run b:module
  • pnpm run b:types
  • pnpm run lint (0 errors)
  • git diff --check

Fixes #3064

Summary by CodeRabbit

  • Bug Fixes

    • Prevented an actively used rendering instance buffer from being prematurely reclaimed during resource cleanup.
    • Ensured the instance buffer is properly released when the rendering system is shut down.
  • Tests

    • Added coverage to confirm the buffer remains alive after engine garbage collection, and is destroyed during rendering teardown.

@sun-nocat
sun-nocat requested a review from GuoLei1990 July 12, 2026 15:55
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dc662759-2369-4863-a2f4-f8339a034429

📥 Commits

Reviewing files that changed from the base of the PR and between 207d035 and 882db26.

📒 Files selected for processing (1)
  • packages/core/src/RenderPipeline/InstanceBuffer.ts
💤 Files with no reviewable changes (1)
  • packages/core/src/RenderPipeline/InstanceBuffer.ts

Walkthrough

InstanceBuffer.setLayout() marks its allocated buffer as ignored by resource garbage collection. A regression test verifies GC preservation and release during batcher teardown.

Changes

Instance buffer lifetime

Layer / File(s) Summary
GC lifetime and regression coverage
packages/core/src/RenderPipeline/InstanceBuffer.ts, tests/src/core/RenderPipeline/InstanceBuffer.test.ts
Allocated instance buffers are excluded from ordinary GC, while tests verify survival through GC and destruction during batcher teardown.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A rabbit guards buffers through GC’s little sweep,
They stay alive while render tasks leap.
When the batcher rests at the end of the day,
Explicit teardown sends them away.
Hop, hop—safe and sound!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: preserving the instance buffer during resource GC.
Linked Issues check ✅ Passed The code and regression test match #3064 by keeping InstanceBuffer alive through gc and still allowing explicit destruction.
Out of Scope Changes check ✅ Passed The changes stay focused on the buffer lifetime fix and its regression test, with no unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch xingyi/fix-instance-buffer-gc

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.66%. Comparing base (75af66f) to head (882db26).
⚠️ Report is 3 commits behind head on dev/2.0.

Additional details and impacted files
@@             Coverage Diff             @@
##           dev/2.0    #3065      +/-   ##
===========================================
+ Coverage    79.52%   79.66%   +0.13%     
===========================================
  Files          904      904              
  Lines       101168   101221      +53     
  Branches     11377    11431      +54     
===========================================
+ Hits         80456    80638     +182     
+ Misses       20528    20399     -129     
  Partials       184      184              
Flag Coverage Δ
unittests 79.66% <100.00%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

GuoLei1990

This comment was marked as outdated.

@GuoLei1990 GuoLei1990 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

二轮审查 @ 882db26c — 唯一 P3 已闭环,LGTM

自首轮 207d03584c 起线性 +1 commitcompare ahead_by:1/behind_by:0 无 force-push):882db26c chore(core): remove instance buffer comments,仅 InstanceBuffer.ts 删 2 行注释、isGCIgnored=true 逻辑逐字不变。

首轮唯一 [P3](新增两行 // 注释末尾带句号、不合本目录 // 惯例)作者选择整段删除这两行 // 注释——闭环,本目录 // 无句号惯例恢复。核心修复(InstanceBuffer 裸 buffer 打 isGCIgnored=trueResourceManager.gc() 回收 active GPU-instancing buffer)与首轮逐字一致,本轮零逻辑改动无需复核。CI 全绿。

无 P0/P1/P2/P3。可合。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants