Depth buffer problems on Galaxy S6 after update from v3.15.1 to v3.17

I recently updated my project from using cocos2d-x v3.15.1 to using v3.17, and since doing so, I see lots of depth buffer glitches when running on a Galaxy S6. That’s my only Android test device, so the problem may be general to Android. By Depth buffer glitches, I mean in places - where two objects are close to each other, I can see through one object to the object behind, and where that occurs changes with the viewing position. All looks fine still running on the Windows-based simulator.

At first I thought the problem might be specific to my project because I’m defining my own materials, but I changed my project to not load any bespoke materials and the problem persists.

Can anybody throw some light on what may be the cause? I assume not everyone is seeing this, otherwise there would be an outcry.

You’re missing some info, like which version of Android is installed on that Galaxy S6? Are you using global Z or local Z for sorting? Do you have a simple project to use as a test case that reproduces the issue?

Hi R101

The Android version is: 7.0

I don’t believe I’m calling any functions to do with sorting. The problems are within a 3D scene and look to be to do with depth buffer resolution rather than a render order problem: it is not that whole object appear incorrectly above another; it is just parts of the objects.

I don’t have a simple test case, but I will create one and post here again when I have it.

Not sure why it would happen on a specific device, or from 3.15->3.17, but it could be a precision issue.
You could try experimenting with near/far values in the camera matrix init (below). Try changing to -256, 256 or -256, 1024, for example. It’s possible that device has certain unusual range limits?

Unfortunately this requires engine code change, but if you can do that there is probably a workaround that can be had using the public API.

Also, maybe a 16-bit depth buffer is being used instead of 24-bit … though not sure why you’d see that if you made no changes beyond upgrading from 3.15->3.17?

    GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    glContextAttrs.depthBits = 16;
#endif
    cocos2d::GLView::setGLContextAttrs(glContextAttrs);

Here’s an archive of very cut down version of my project:http://download.glidos.net/iToBx.zip

It shows a platform built as a matrix of square slabs. You can rotate around it by dragging and zoom in and out by pinching. The problem shows as the edges of the slabs popping in and out at certain viewing positions.

Thanks for the replies so far. I will try out your suggestions.

I can roll back to 3.15 easily enough. I’ll recheck and report back.

I’ve realised the other big change I’ve made is to allow Android Studio to update. I mostly work with the Windows simulator and test on Android rarely, so on every test there are updates. I tried rolling my cocos2d-x project back to v3.15, but - presumably because of updating AS - I get the build error “cocos2d-x cannot find symbol method setAudioFocus”.

In any case, this is a problem that has arisen indepentently of any of my projects code changes, so it may still be important.

I cannot find that code snippet anywhere in my project. Where did you find it? My project is lua based: could that be why I don’t have it.

I rolled back, but my fully updated Android Studio really doesn’t like v3.15-based projects. I tried bringing the project up to date, but then ran into a problem with GCC no longer being supported and didn’t know how to work around that.

Do you have error logs? I don’t remember too many issues going from GCC to clang once it was fully supported. However, this is unacceptable and sucks on your end for sure, don’t get me wrong.

For rolling-back your project have you ever built from the command-line? I would guess your project is still setup as an ndk-build project. You could probably still build using cocos deploy or maybe ndk directly ndk-build ...??

I’ve found the later versions of Android Studio to work well, but I think I did have to massage the project.gradle and app.gradle.

Sorry, I prob won’t be much help here, but if you give more info maybe??

I, perhaps foolishly, took on some more Android Studio updates, and now my previously working - other than the depth buffer problem - app, produces a blank black screen. Also cpp-tests crashes, so I’m not sure what I should try next.

@Glidos Do you have your project in source control, so you can check what, if any, changes were made to your Android project files by Android Studio? If so, roll back to a revision you know works, and try again.

For some reason the black screen issue seems familiar, like I’ve come across it before, but using the latest Android Studio beta versions (3.2 or 3.3). I can’t quite recall if I managed to get it working, and perhaps that’s why I’m still using Android Studio v3.1.4.

It is in source control so I can back out the changes, but the updated Android Studio requires those changes and wont build my project without them. I think it’s the gradle plugin that is problematic. Maybe there’s a way to downgrade it?

That’s precisely why I asked the question regarding source control. If you compare your working files with a previous revision in source control, you will see exactly which files were changed by Android Studio when it upgraded the gradle plugin. All you have to do is revert those files to the previous revision, or manually change the entries, and then when you open the project in Android Studio, don’t let it upgrade them again until you are certain you can compile and run your app without issues.

Once your app is running correctly, upgrade the gradle plugin manually, and go through the process of building your app again to see if it causes issues.

Look in [projectfolder]/proj.android/build.gradle, and you will see this entry. Change the value to what you need (for instance, this is from my project, using gradle 3.1.4):

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'
}

Which version of Android Studio are you actually using?

Yes, I understand what you are suggesting. When I revert my the changes, Android Studio cannot open my project and show the error “No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android”

I don’t know how to update the project to get around that, other than alllowing Android Studio to update the project, which leads to it changing the gradle version. I think the error may be because of the NDK version. I may try to load an older one.

I’m using Android Studio 3.2

I had way too many issues with Android Studio v3.2, so I stopped using it for the time being, and just stuck with v3.1.4. Also, the NDK that works with my setup is r16b.

I presume you’re running NDK 17 or newer, which seems to have something to do with the mips64el-linux-android issue, according to a quick search online.

I’ve now installed Android Studio v 3.1.4 and had it install the skd and ndk. It installed a too recent version of the ndk so I donwloaded r16b and changed the project’s ndk path to match the download. Still I have build errors. I created a completely new cocos v3.17 project and tried to build it. I get this:

Build command failed.
Error while executing process C:\Users\paul\Downloads\android-ndk-r16b-windows-x86_64\android-ndk-r16b\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\paul\Documents\Git\iToBx\iToB\frameworks\runtime-src\proj.android\app\jni\Android.mk NDK_APPLICATION_MK=C:\Users\paul\Documents\Git\iToBx\iToB\frameworks\runtime-src\proj.android\app\jni\Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 APP_PLATFORM=android-14 NDK_OUT=C:/Users/paul/Documents/Git/iToBx/iToB/frameworks/runtime-src/proj.android/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=C:\Users\paul\Documents\Git\iToBx\iToB\frameworks\runtime-src\proj.android\app\build\intermediates\ndkBuild\debug\lib NDK_TOOLCHAIN_VERSION=clang -j8 NDK_DEBUG=1 C:/Users/paul/Documents/Git/iToBx/iToB/frameworks/runtime-src/proj.android/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/libcocos2dlua.so}
[armeabi-v7a] Compile++ arm  : cocos2d_lua_static <= lua_cocos2dx_physics3d_manual.cpp
[armeabi-v7a] Compile++ arm  : cocos2d_lua_static <= lua_cocos2dx_physics3d_auto.cpp
[armeabi-v7a] Compile++ arm  : cocostudio_static <= CCActionFrame.cpp
[armeabi-v7a] Compile++ arm  : cocostudio_static <= CCActionFrameEasing.cpp
[armeabi-v7a] Compile++ arm  : cocostudio_static <= CCActionManagerEx.cpp
[armeabi-v7a] Compile++ arm  : cocostudio_static <= CCActionNode.cpp
[armeabi-v7a] Compile++ arm  : cocostudio_static <= CCActionObject.cpp
[armeabi-v7a] Compile++ arm  : cocostudio_static <= CCArmature.cpp
[armeabi-v7a] Compile++ arm  : cocostudio_static <= CCBone.cpp
In file included from C:/Users/paul/Documents/Git/iToBx/iToB/frameworks/runtime-src/proj.android/app/jni/../../../../cocos2d-x/cocos/scripting/lua-bindings/proj.android/../auto/lua_cocos2dx_physics3d_auto.cpp:3:
C:/Users/paul/Documents/Git/iToBx/iToB/frameworks/runtime-src/proj.android/app/jni/../../../../cocos2d-x/cocos/3d/..\physics3d/CCPhysics3D.h:57:10: fatal error: 'bullet/BulletCollision/CollisionDispatch/btGhostObject.h' file not found
#include "bullet/BulletCollision/CollisionDispatch/btGhostObject.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[armeabi-v7a] Compile++ arm  : cocostudio_static <= CCArmatureAnimation.cpp
1 error generated.
make: *** [C:/Users/paul/Documents/Git/iToBx/iToB/frameworks/runtime-src/proj.android/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/objs-debug/cocos2d_lua_static/__/auto/lua_cocos2dx_physics3d_auto.o] Error 1
make: *** Waiting for unfinished jobs....
In file included from C:/Users/paul/Documents/Git/iToBx/iToB/frameworks/runtime-src/proj.android/app/jni/../../../../cocos2d-x/cocos/scripting/lua-bindings/proj.android/../manual/physics3d/lua_cocos2dx_physics3d_manual.cpp:33:
C:/Users/paul/Documents/Git/iToBx/iToB/frameworks/runtime-src/proj.android/app/jni/../../../../cocos2d-x/cocos/3d/..\physics3d/CCPhysics3D.h:57:10: fatal error: 'bullet/BulletCollision/CollisionDispatch/btGhostObject.h' file not found
#include "bullet/BulletCollision/CollisionDispatch/btGhostObject.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [C:/Users/paul/Documents/Git/iToBx/iToB/frameworks/runtime-src/proj.android/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/objs-debug/cocos2d_lua_static/__/manual/physics3d/lua_cocos2dx_physics3d_manual.o] Error 1

If you haven’t yet, you may need to run python download-deps.py since the externals are updated every few versions.

I think that’s needed only if you wish to rebuild cocos2d-x from source, but I’ll give it a try all the same.