pmndrs / three-stdlib

📚 Stand-alone library of threejs examples designed to run without transpilation in node & browser
https://npmjs.com/three-stdlib
MIT License
733 stars 119 forks source link

`new Lut()` crashes with error "Cannot read properties of undefined (reading 'toReference')" #367

Closed nikoprotic closed 6 months ago

nikoprotic commented 6 months ago

Problem description:

calling new Lut() crashes my program.

Relevant code:

import React, { useEffect } from "react";
import { Lut } from "three-stdlib";

export const MyReactComponent = (props: MyProps): JSX.Element => {
  const [lut, setLut] = useState<Lut>(null);

  useEffect(() => {
    let newLut = new Lut();
    setLut(newLut);
  }, []);

  return <></>;
}

Suggested solution:

It seems like the issue is here: https://github.com/pmndrs/three-stdlib/blame/bdfe295d6e725a8109b49d7ccf266a2b05ab4424/src/math/Lut.js#L60C57-L60C57. ThreeJS expects a LinearSRGBColorSpace of "srgb-linear", not "linear-srgb". This can be seen in their repo here: https://github.com/mrdoob/three.js/blob/0bc990f5f728552c6cc3931d1b44afa9718aef40/src/constants.js#L162. This results in the error being thrown from here: https://github.com/mrdoob/three.js/blob/0bc990f5f728552c6cc3931d1b44afa9718aef40/src/math/ColorManagement.js#L93.

github-actions[bot] commented 6 months ago

:tada: This issue has been resolved in version 2.30.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

nikoprotic commented 6 months ago

@CodyJasonBennett insane turn-around speed, thank you! Though I am a bit salty that I couldn't get a chance to contribute a fix myself...

CodyJasonBennett commented 6 months ago

You're welcome to make it a shared constant so this doesn't regress with future code. Fixed this issue before in a few spots. We hardcode SRGBColorSpace, LinearSRGBColorSpace and the older sRGBEncoding and LinearEncoding all around. Can't import it from three.js since it's unknown whether the export is there.