rastapasta/react-native-gl-model-view

Example flickering on Android

Closed this issue · 3 comments

Hi,

I tried copying the example and running on two physical devices (Motorola g4 play and Samsung Tablet SM-T530). The models flicker at a very fast frame rate (60fps?) basically disappearing and showing the background. This happens until you lock the screen at which point you can see the model solidify briefly then when you unlock it reactivates and goes back to flickering.

On a virtual device (genymotion) the models don't even appear.

Everything works fine on iOS simulator.

I'm using JDK that comes with Android Studio and compiling with 27.0.1 build tools for android. I haven't changed any project settings whatsoever but I did copy the example js files into a newly created react native project using react-native init as on android the sym linking doesn't work into the node_modules dir so it won't compile.

Using master from github. From package.json:

"dependencies": {
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-gl-model-view": "git+https://github.com/rastapasta/react-native-gl-model-view.git"
},

Same happens with current release.

The only thing of note is that because react-native init uses an older gradle version I have to change this project's build.gradle lines 32, 33 from implementation.....to compile....

Any clues on what could be causing this issue?

Ok I spent ten minutes reading up on GL on Android and worked it out. I'm surprised no one noticed this before.

This file:

https://github.com/rastapasta/react-native-gl-model-view/blob/master/android/src/main/java/com/rnglmodelview/RNGLModelViewRenderer.java

onDrawFrame:

You have to render something every time this is called otherwise you risk a blank frame (according to some reading around the behaviour is undefined - may render blank or previous frame) which is exactly what is happening.

The reason it may not have been picked up is because of the undefined behaviour. Might work on certain SDK/Android versions/Devices etc.

Simple fix was to remove the conditional. I suspect it has no impact on anything else but I'll test more thoroughly before submitting a pull request.

There's also something about dirty rendering which might be why this conditional worked previously as well. I suspect potentially something is causing it to be dirty more often. This may cause performance issues if it's continuously rendering. I'll keep digging. It's been a good 20 years since I was a child wanting to recreate games like Quake since I've looked at GL stuff so I'm rusty.

I also plan on adding the ability to take an image snapshot and modify the lighting which I'll submit a PR for at the same time.

Another one to add to the list is that the textures are loaded in with black as the default transparency so apart from things looking rough around the black where there's a gradient you can see whatever is behind the black.

Easy fix is line 186: RNGLModelView.java replace existing line with:

texture = new Texture(textureStream, true);

Will also include in pull request. I'm sorting through more issues with lighting being inconsistent with iOS , filtering being awful and actually plan to add a snapshot feature once I sort through all the issues.

Aloha & thanks for all the feedback @shokimble! Sorry that it took so long ;)
Just merged @JavanPoirier's pull request - should fix this issue.
Cheers!