Skip to content

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

@Kethatril

Description

@Kethatril

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

const onBeforeCompile = material.onBeforeCompile.bind(this);

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions