-
Notifications
You must be signed in to change notification settings - Fork 73
Android black textures #21
Comments
I have encountered the same issue where textures sporadically fail to load, thereby rendering a black texture instead of the desired image. Please find linked sample code that helps further illustrate this issue. The code creates a 5 x 5 grid of meshes, using three.js and the react-native-webgl libraries. Each mesh consists of a plane geometry and material created from an image texture. To eliminate the possibility of the issue being related to image size or format, every texture references the same image. The expected output would be 25 properly rendered images, placed adjacent to one another. However, the actual output consists of some meshes having a black texture instead, as shown in the linked image. Testing has been conducted on the following platforms:
Testing was also conducted on an iPhone 6S (running iOS 10.3.3), but the issue was not present on it. For reference, the following relevant libraries were linked to the project when testing:
Please let me know if you require any further information. If you have any ideas regarding what may be causing this issue, let me know and I can help update the code / submit a pull request afterwards. |
ok guys, I plan to investigate the hell out of this tomorrow :) #motivation |
I tested the latest commits on Android, and it looks like the issue is still present. Using the earlier grid example, some images still sporadically show up as black textures while others appear to render correctly. |
yes exactly. see my comment #16 (comment) It's hard for me to see where things are wrong, if you want to investigate on your side feel free. I also have no idea why sometimes the image appears twice, this feels to be a bad concurrency issue, I wonder if it's in the CPP low level code itself. I hope @nikki93 can help on this, maybe it would be great if we could try to replicate this example in Expo EXGLView itself (that have slightly different API). i'll try to port things over Snack |
I have this https://snack.expo.io/HJE_kof3- that seems to work on Android (I can't repro the present bug. so maybe it means it's a concurrency issue on react-native-webgl side, the image loader impl) however it renders white on iOS (same as in react-native-webgl NineTextures example) and I have no idea why – it looks like iOS have trouble supporting many textures at the same time? |
Are there other ways to load images on Android so we can test it ? |
for the iOS bug, i'm delegating the investigation to expo/expo#728 – for Android, i'll investigate |
@Kernael i'm not sure to follow what you mean? |
Just wondering if there is another way than |
for the Android bug: you can also use a typed array, but at this point I don't think there will be issues with typed array since it seems to works ok in expo. probably just an issue in the current implementation. going to investigate this afternoon |
in my current investigation the bug seems around this call that never succeed in some random cases.. https://github.com/react-community/react-native-webgl/blob/b7aa3cfc18ebcc2aa226d2dfa41c9eb5a064ff9a/android/src/main/java/fr/greweb/rnwebgl/RNWebGLTextureBitmap.java#L26 To me it looks like a classical "race condition" issue. between 2 part of the code:
there are some I don't have a lot of experience into dealing with Java race condition, do you? I'll try to document myself.
|
Could you provide an example on how to do so, based on the snippet I provided on the first post of this issue ? Thank you for your awesome work ! |
so as far as I understand, it's not correct to use a ArrayList, needs to use one of java.concurrent.* list/queue |
I (think to) have fixed the concurrent issue, but still some cases it fails. continuing investigating... |
Any particular reason why you have to invoke |
I'm going to try to help since I have quite a bit of experience with Java concurrency. |
Also you really shouldn't ever leak "this" to other scopes in constructors (RNWebGLView, RNWebGLTextureBitmap). This can cause the object to be used while it still hasn't been properly created. Only pass this to other objects or methods outside the constructor. |
thanks for your help :) this project is definitely looking for more Java experts, it is backed with many langs (c++ / objc / java / js) there are probably a lot to improve in each lang paradigm :) interesting about "this" to not use in constructor 👍 |
summary of the problemBTW here is a simple way to replicate the bug of this issue: open the project but instead it tends to render black image AND/OR twice the image in 2 different textures. there might be multiple bugs involved by this. it sounds to be a race condition in Java, but it might be a race condition in C++ too (across the GL calls). |
I'm getting closer to the problem I think with this commit: 17857f5 GL is stateful so I had to "restore" the bounded texture to not affect user's code.. I think the twice-the-same-image issue is gone however there are still some black case.. I wonder if this black case is related to that problem as well (like maybe I just restore to the null value now?). still maybe that means we don't schedule that code at the correct time..? |
Hi again everyone. I think I have FINALLY fixed the problem. Feel free to comment here if you experience the bug is not fixed. otherwise, we'll schedule a new release soon. |
Please do not closed the issue without confirmation that this is actually fixed.
I think I may have found a bug : the documentation for Facebook's BaseBitmapDataSubscriber states that the Bitmap object in the callback is only available in the scope of the method and may be reused later. But you pass it to your RNWebGLTextureBitmap in RNWebGLTextureImageLoader.loadWithConfig I wrote But this does not solve the problem. It is necessary though |
Yet another potential concurrency bug : in RNWebGLTextureLoader.loadWithConfigAndWaitAttached :
|
yeah sorry, my example image was actually before the bug was fixed*. i am not able to have the bug anymore (a few try, not meaning it's 100% guarantee it's fixed). oh yeah I was wondering if I had or not to .copy, I think it's definitely safer to copy, very good point. ok i'll try to address these points, thanks a lot for these feedback!! |
@odusseys I added two commits to address these points, thanks a lot for your valuable feedbacks :) |
this was supposed to address rnc-archive#16 rnc-archive#21 but still having issues
@Kernael have you tried the master version to see if it fixes the issue (at least on Android) |
The issue appears to be fixed based on preliminary testing. Thank you. |
I did not have the time to thoroughly test this but based on what I could see, the issue seems to be fixed ! |
As discussed here #16 , textures loaded with
gl.getExtension('RN').loadTexture()
sometimes fails to load on Android (rendering a black mesh)The text was updated successfully, but these errors were encountered: