postprocessing icon indicating copy to clipboard operation
postprocessing copied to clipboard

[v7] Error occurs when the scene contains troika-three-text

Open Kethatril opened this issue 1 year ago • 1 comments

Description of the bug

When an instance of troika-three-text is visible in the scene the Geometry pass fails with Uncaught TypeError: this.customProgramCacheKey is not a function It occurs because at this line https://github.com/pmndrs/postprocessing/blob/54a2662b4080522a3fa8fde1def063aa3589d968/src/passes/GeometryPass.ts#L382 the previous onBeforeCompile function is bound to the Geometry pass so this is incorrect.

However if you bind it to the original material instead you get a stack overflow. Troika-three-text has a system in place that grabs any new onBeforeCompile function that gets applied and then runs it after it runs it's own onBeforeCompile. So if you then run the stored onBeforeCompile on the postprocessing side you get into a loop.

Not binding to this and then only running onBeforeCompile (possibly binding it back to the original material or this if there is a reason for doing so) if it doesn't equal material.onBeforeCompile seems to avoid the issue and still works for other non troika-three-text materials.

To reproduce

Add an instance of troika-three-text to the scene

Expected behavior

For render not to fail when there is an instance of troika-three-text in the scene

Library versions used

  • Three: [0.168.0]
  • Post Processing: [7.0.0-beta.4]
  • troika-three-text: [0.49.1]

Kethatril avatar Sep 29 '24 19:09 Kethatril

Thanks for the report!

There's no specific reason for the bind(this) part, so changing it would be no problem. Would you like to create a PR? Otherwise, I'll take care of it when I find the time.

vanruesc avatar Sep 30 '24 19:09 vanruesc

Troika-three-text has a system in place that grabs any new onBeforeCompile function that gets applied and then runs it after it runs it's own onBeforeCompile.

That's actually quite intrusive. Looks like adding a workaround really is the only option. Thankfully, the onBeforeCompile solution in GeometryPass is only temporary.

vanruesc avatar Oct 31 '24 22:10 vanruesc

Fixed in v7.0.0-beta.5

vanruesc avatar Feb 09 '25 14:02 vanruesc