fix: unwrap Filter shell in PostProcess2D.addEffect to avoid effectInit crash(PostProcess2D.addEffect 兼容直接传入 Filter 外壳,自动解包避免 effectInit 报错) - #2335
Open
xiaosong1985 wants to merge 1 commit into
Conversation
…it crash(PostProcess2D.addEffect 兼容直接传入 ColorFilter/GlowFilter/BlurFilter 等 Filter 外壳,自动解包为真正的 effect,避免调用 effectInit 时报错) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
开发者反馈:直接调用
PostProcess2D.addEffect(filter)或postProcess.effects = [filter]时报错TypeError: effect.effectInit is not a function。原因
LayaAir 3.4 中
ColorFilter/GlowFilter/BlurFilter只是Filter外壳,真正的PostProcess2DEffect需要通过filter.getEffect()取出(内部_effect2D)。Filter基类没有effectInit/destroyed/singleton等PostProcess2DEffect成员。h5game 旧代码直接把Filter塞进postProcess.effects/addEffect,到 3.4 就会在addEffect内部调用effect.effectInit(this)时抛异常。effectssetter 内部也逐个走addEffect,同样中招。修复
在
PostProcess2D.addEffect入口做一次兼容解包:入参是Filter时自动取getEffect()。addEffect是唯一收敛点,effectssetter 一并覆盖;Sprite.filters本就传getEffect()的正确路径,instanceof Filter为 false 原样通过,幂等无副作用。验证
在基于 3.4 引擎的 WxWebGPU 工程中复现并验证:
addEffect(filter)与effects=[filter]两条路径均抛effect.effectInit is not a function。ColorFilter真正生效(测试色块变灰),说明 effect 被正确解包并进入渲染管线。仅改动一个文件
src/layaAir/laya/display/PostProcess2D.ts,不涉及子模块。🤖 Generated with Claude Code