Don't render when graphics is disabled #249
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe the change
It is possible (observed in apps using Babylon React Native) for graphics to be re-enabled after being disabled while the engine instance and
EngineVieware being torn down. As far as I can tell, this is a timing issue that was probably introduced with the threading changes where rendering no longer happens on the JS thread. It seems to just depend on the timing of when React Native removes the view. The result of this is that if graphics is re-enabled, bgfx allocates a bunch of memory, and so a React Native app can end up with a lot of extra memory pressure even when Babylon is not in use.The fix for this is to simply keep track of whether rendering has been explicitly enabled/disabled, and only allow the view to be rendered when rendering is enabled (attempting to render a frame will automatically enable rendering).
Screenshots
N/A
Documentation
N/A
Testing
I went through the tests on Android and iOS. I think it is unlikely that this would result in a regression on Windows.