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

How do you dispose of the engine? #65

Closed
PaulRyan97 opened this issue May 18, 2020 · 4 comments
Closed

How do you dispose of the engine? #65

PaulRyan97 opened this issue May 18, 2020 · 4 comments

Comments

@PaulRyan97
Copy link

Hi,

I'm looking for a way to dispose of the engine once my component containing it unmounts. I thought this might be done by default but it looks like it's not. Is there anyway to access the engine object from say a useEffect hook in the component the engine is declared in?

@brianzinn
Copy link
Owner

Good catch - above commit should resolve and dispose automatically. You could dispose yourself by getting the Engine from the context and something like a useEffect returning () => engine.dispose(); I'll try to get an NPM out soon - there are some other pending changes. That code would itself need to be contained inside the Engine JSX markup to have the engine available on the context. HTH

@PaulRyan97
Copy link
Author

You could dispose yourself by getting the Engine from the context and something like a useEffect returning () => engine.dispose();

I had tried something like that but I seem to keep getting a null value back for the Engine object. Do you have an example of how you would see this workaround working?

@brianzinn
Copy link
Owner

You can do scene.getEngine() or get engine from context before Scene component (inside Engine). Inside Scene component is where the reconciler overwrites the context. It’s a bit tricky how React resets context Inside the reconciler. Engine will be disposed automatically when the Engine component unmounts in the code fix :)

brianzinn added a commit that referenced this issue May 31, 2020
…ed an additional check before disposing the Scene #65
@brianzinn
Copy link
Owner

Should be fixed in react-babylonjs@2.2.1 - please re-open if you have any more questions or this is not resolved for you. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants