Skip to content

fix(shader): strip leading zeros from ACTINIUM_VERSION macro value - #112

Merged
DHJComical merged 1 commit into
mainfrom
fix/actinium-version-macro-leading-zero
Sep 3, 2026
Merged

fix(shader): strip leading zeros from ACTINIUM_VERSION macro value#112
DHJComical merged 1 commit into
mainfrom
fix/actinium-version-macro-leading-zero

Conversation

@DHJComical

Copy link
Copy Markdown
Owner

问题

生产环境偶发:进世界后任何光影包都无法载入,切换光影包时提示「已使用光影包:(off)!」,换任何光影包均无效(触发类似重载,但始终回退到原版渲染)。

根因

生产日志堆栈:

RuntimeException: Unexpected LexerException processing macros
    at PropertiesPreprocessor.preprocessSource(PropertiesPreprocessor.java:45)
    at ShaderProperties.<init>(ShaderProperties.java:132)
    at ShaderPack.<init>(ShaderPack.java:232)
    at Iris.loadExternalShaderpack(Iris.java:574)
Caused by: org.anarres.cpp.LexerException: Warning at 1:8: Decimal constant starts with 0, but not octal: 000058359
    at org.anarres.cpp.Preprocessor.addMacro(Preprocessor.java:380)

证据链:

  • StandardMacros.makeActiniumVersion() 把版本 alpha-0.0.5-da83c59 编码为 ACTINIUM_VERSION=000058359:sha 段 da83c59 以字母开头被当作 prerelease 抽出数字 8359,而 major=0 时编码值恒以 0 开头。
  • jcpp 的 addMacro(name, value) 在内部新建无 listener 关联的 lexer 解析宏值:多字符、0 开头、含 8/9 的数字被当作非法八进制常量,直接抛 LexerException
  • 三参 preprocessSource 的 environmentDefines 循环没有容错,异常一路抛到 ShaderPack.<init>。environment define 与具体包无关,因此所有光影包都加载失败,表现为「换包无效」。
  • 是否触发取决于构建版本号 sha 段是否被解析出含 8/9 的数字 → 偶发;dev 环境 Tags.VERSION 无数字三元组,恒返回 "0" → dev 无法复现。
  • fix(shader): tolerate jcpp lexer warnings when defining property macros #61(e07dd15)安装的 pp.setListener(...) 对该路径无效——addMacro 内部 lexer 不关联 Preprocessor 的 listener(生产代码在行 38 装了 listener、行 45 仍抛异常,行号完全吻合)。真正起保护作用的是 catch,本 PR 一并修正注释并移除无效调用。

改动

  • StandardMacros:编码值去前导零(00005835958359),数值语义不变,从根源消除非法八进制常量。
  • PropertiesPreprocessor:两个 overload 中宏值解析失败时跳过该宏并 logger.warn(含宏名/值),不再让整个光影包加载失败;两参 overload 的 catch 移入循环内(原来首个坏宏会导致后续宏全部丢失);printStackTrace() 统一换成 logger.warn
  • 测试:新增 StandardMacrosVersionTest(版本编码回归 4 例);PropertiesPreprocessorTest 补充三参 overload 用例(复现生产崩溃路径)。

验证

  • TDD:修复前 3 个用例按预期失败(三参用例抛出与生产同型的 RuntimeException ← LexerException 链),修复后 7 个用例全绿。
  • ./gradlew build --no-daemon 全绿。

The encoded mod version starts with '0' whenever major is 0 (e.g.
alpha-0.0.5-da83c59 encoded as "000058359"). jcpp lexes macro values
inside addMacro through an internal lexer source that has no listener
attached, so a leading-zero value containing 8/9 is rejected as a
malformed octal constant and the LexerException aborted the whole shader
pack load — every pack failed and the game reported the pack as (off).

- StandardMacros: strip leading zeros from the encoded ACTINIUM_VERSION;
  the numeric value is unchanged.
- PropertiesPreprocessor: skip a macro whose value fails to lex and log a
  warning instead of aborting the pack load, in both overloads; the
  two-arg overload no longer drops the remaining macros after the first
  bad one. Replace printStackTrace with logger.warn. Drop the misleading
  listener setup and comments from e07dd15 — the preprocessor listener is
  never consulted by addMacro, the catch is what actually protects the
  load.
@DHJComical
DHJComical merged commit e742611 into main Sep 3, 2026
1 check passed
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.

1 participant