Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange flashing when remounting images #79

Open
Ledzz opened this issue Jun 7, 2024 · 2 comments
Open

Strange flashing when remounting images #79

Ledzz opened this issue Jun 7, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Ledzz
Copy link
Contributor

Ledzz commented Jun 7, 2024

See repro here:
https://stackblitz.com/edit/vitejs-vite-eafhmw?file=src%2Fmain.tsx

And the recording:
https://github.com/pmndrs/uikit/assets/9379701/81269900-f3d8-433c-92d5-a8828a915bf6

To reproduce, you should load you system (I've opened a bunch of tabs and enabled 6x CPU throttling).
Then click on the red square on the top left.

The page flashes I guess when mounting images (if I remove Icon component, there's no flash).
I guess the plane is spawn at zero coordinates and then it moves.

I can try to fix it if you know what the problem is:)

@bbohlender bbohlender added the bug Something isn't working label Jun 8, 2024
@Ledzz
Copy link
Contributor Author

Ledzz commented Jun 10, 2024

I've managed to hack it by loading texture outside of the image and hiding the image until texture is loaded:

export const HackedImage: FC = ({ image, ...props }) => {
  const [texture, setTexture] = useState<Texture | null>(null);
  const [imageRef, setImageRef] =
    useState<ComponentInternals<ImageProperties> | null>(null);
  const { visibility } = useDefaultProperties() ?? {};

  useEffect(() => {
    getTexture(image).then(setTexture);
    // TODO: dispose texture
  }, [image]);

  return texture ? (
    <Image
      src={texture}
      {...props}
      visibility={!texture || visibility === "hidden" ? "hidden" : "visible"}
      ref={setImageRef}
    />
  ) : null;
};

@bbohlender
Copy link
Contributor

with a probability of 99% this happens because the image is attached but its matrix is not updated for a very short time. In general all matricies should be 0 initiallially, to prevent rendering before beeing positioned correctly. This should be fixed with the new archiecture that mounts to the mesh using the ref callback and set the matrix to 0 there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants