rnc-archive / react-native-webgl

DEPRECATED: use expo-gl – Implements WebGL for react-native
296 stars 73 forks source link

Attempt to read from field 'int fr.greweb.rnwebgl.RNWebGLTexture.ctxId' on a null object reference #56

Closed AndyEsser closed 4 years ago

AndyEsser commented 6 years ago

I have a React Native component which uses react-native-webgl for rendering a game. This component can be unloaded via navigation and the user go back into it again.

During testing a Samsung S8 (Physical) and a Nexus 5 (Emulator) I had no issues, however deploying it to a Samsung S6 ends up throwing the above error after a few restarts of the game within the application.

My Game component (responsible for handling all the react-native-webgl has a 'componentWillUnmount' method which appears to get called each time the component is unloaded via React Native, as it should. In this method I am going through and deleting all my WebGL Textures, and then setting my this.gl variable to null (this is the object that was passed to the component on onContextCreate).

I presume that this error is being caused by some sort of race condition between React Native unloading the component, and RNWebGL doing it's cleanup.

I've attached a screenshot of the issue. Now I suspect a simple Null check in the Native code might avoid this issue happening, but I wan't to check that I shouldn't be cleaning up some other way, or if I might be missing something obvious

screen shot 2018-05-01 at 14 11 14