Skip to content
This repository was archived by the owner on Sep 20, 2026. It is now read-only.

fix(overlays): avoid version-specific scene handle access - #327

Merged
pengx17 merged 1 commit into
masterfrom
codex/scene-runtime-compat
Sep 5, 2026
Merged

pengx17 merged 1 commit into
masterfrom
codex/scene-runtime-compat

Conversation

@pengx17

@pengx17 pengx17 commented Sep 5, 2026

Copy link
Copy Markdown
Member

Context

点击 Collection 图标或按 Tab 后面板不显示。当前游戏的 Unity Player.log 持续报告 MissingMethodException: int UnityEngine.SceneManagement.Scene.get_handle(),调用点为 OverlayPanelHost.Update 和 dock 按钮的 LateUpdate

项目通过 UnityEngine.Modules 编译时绑定到旧版返回 int 的 getter,而已安装 Unity 6.3 的 Scene.handle 返回 SceneHandle。构建成功不能证明运行时方法签名兼容。

方案讨论

场景缓存只需要判断是否为同一个场景,无需读取 handle 数值。直接缓存 Scene,并使用签名未改变的 Scene.op_Equality(Scene, Scene),避免引入反射或特定 Unity 版本类型。

最终方案

  • OverlayPanelHost 的场景 token 缓存比较 Scene 值,保留 loaded 检查及原有 token 内容。
  • ActiveSceneNameCache 同样比较 Scene 值,修复 dock 布局刷新中的相同异常。
  • 新增编译产物检查:读取实际 BazaarPlusPlus.dll 的 PE metadata,禁止 Scene.get_handle 引用并确认使用 op_Equality,防止源码能编译但运行时找不到方法的回归。

验证情况

  • 独立分支基于 master,仅 3 个相关文件;不包含 Steam Timeline 修改。
  • run.sh build Release:通过,0 warning / 0 error。
  • RuntimeIntegration.Tests 定向运行 SceneRuntimeCompatibilityTests:1 项通过。
  • CSharpier 检查与 git diff --cached --check:通过。
  • 已备份并替换本地测试 DLL,4 个文件哈希一致;用户随后反馈“可以,提PR,并merge”。

已知局限 / 后续工作

本次修复 Scene.handle 的二进制签名兼容性;图标间距是否还有独立布局问题需以实机结果为准。

Copilot AI lite review requested due to automatic review settings September 5, 2026 05:53
@pengx17
pengx17 merged commit 3e0176f into master Sep 5, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The functional fix is targeted and backed by a compiled-artifact regression test; only a minor doc-comment tweak was noted.

Pull request overview

This PR fixes overlay panels not appearing on newer Unity runtimes by removing the mod’s runtime binding to the version-specific UnityEngine.SceneManagement.Scene.handle getter and instead comparing Scene values via the stable Scene.op_Equality ABI, with a regression test that inspects the compiled DLL’s PE metadata.

Changes:

  • Replace Scene.handle-based scene-token caching with Scene value comparisons in overlay panel hosting.
  • Update active-scene name caching to avoid Scene.handle access in per-frame callers.
  • Add a runtime integration test that scans BazaarPlusPlus.dll metadata to ensure get_handle is not referenced and op_Equality is referenced.
File summaries
File Description
tests/RuntimeIntegration.Tests/SceneRuntimeCompatibilityTests.cs Adds a PE-metadata guard test to prevent reintroducing Scene.get_handle references.
src/BazaarPlusPlus/GameInterop/Scenes/ActiveSceneNameCache.cs Switches scene cache identity from scene.handle to Scene equality to avoid runtime ABI mismatch.
src/BazaarPlusPlus/Game/OverlayPanels/OverlayPanelHost.cs Updates scene token caching to compare Scene values instead of calling Scene.handle.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

internal static class ActiveSceneNameCache
{
private static int _handle;
private static Scene _scene;
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants