Android glBindTexture crashing in offline trace

I’m trying to get traces working in my android app. Currently the first call to glBindTexture is crashing with the following callstack


 	libPVRTrace.so!CEs2ContextState::SetBoundTexture(unsigned int, unsigned int)()	C/C++<br />
libPVRTrace.so!Es2::_glBindTexture(unsigned int, unsigned int)()	C/C++<br />
libGLESv2_PVRTRACE.so!glBindTexture()	C/C++<br />
>	load_texture()	C/C++<br />
load_png_asset_into_texture()	C/C++<br />
LoadTextureInternal()	C/C++<br />
Render::LoadTexture()	C/C++<br />
BMFLoader::LoadTexture()	C/C++<br />
BaseModel::LoadModel()	C/C++<br />
OrbModel::Init()	C/C++<br />
OrbModel::OrbModel()	C/C++<br />
GMRenderTest::Update()	C/C++<br />
Java_com_novasapiens_Bacchus_BacchusView_GameLoopStep()	C/C++<br />
0x4179ba54	C/C++<br />
0x4179ba54	C/C++
```<br />
<br />
The call succeeds if I delete the profile settings file /data/data/com.powervr.PVRHub/pvrtraceconfig.json<br />
<br />
This is the code that is running:<br />
<code>	GLuint texture_object_id;<br />
glGenTextures(1, &texture_object_id);<br />
assert(texture_object_id != 0);<br />
<br />
glBindTexture(GL_TEXTURE_2D, texture_object_id);<br />
<br />
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);<br />
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);<br />
glTexImage2D(<br />
GL_TEXTURE_2D, 0, type, width, height, 0, type, GL_UNSIGNED_BYTE, pixels);<br />
glGenerateMipmap(GL_TEXTURE_2D);<br />
<br />
glBindTexture(GL_TEXTURE_2D, 0);<br />
return texture_object_id;<br />
</code><br />
The glGenTextures succeeds and I have a valid texture handle to bind to.  I tried moving the glTexParameters up to before the glBindTexture and they still succeeded.  It seems to specifically be an issue with glBindTexture.<br />
<br />
Any assistance would be appreciated.

Hi,



If you can share the following information with us, it will help us investigate the issue.


  1. Which version of the PVRTrace recorder libraries are you using?
  2. What version of Android are you recording your application on?

  3. What graphics API are you using?

  4. What happens if you call glGetError() after each call?

  5. Can you share your pvrtraceconfig.json with us?

  6. Do you also have a pvrtrace.cfg in the same location? The recorder will search for the new style config first (pvrtraceconfig.json), but will fall back to pvrtrace.cfg. This could explain why the behaviour changes when your pvrtraceconfig.json is deleted



Thanks,
Joe

Hi Joe :slight_smile:


  1. Recorder Version: 3.3@2850432
  2. Android version 4.4.2, cyanogen image running on a Galaxy S (GT-I9000)
  3. OpenGL ES 2.0
  4. glError returns GL_NO_ERROR on all calls previous to the glBindTexture
  5. contents of /data/data/com.powervr.PVRHub/pvrtraceconfig.json



    {

    “Tracing”: {

    “OutputFilename”: “/data/data/com.powervr.PVRHub/recordings/%pname.pvrt”,

    “RecordData”: true,

    “OptimiseFileSize”: false,

    “StartFrame”: 0,

    “EndFrame”: 9999,

    “ExitOnLastFrame”: true,

    “ClientBufferRecordFrequency”: 1,

    “SaveFrameBuffer”: false

    },

    “Debug”: {

    “Level”: 1

    },

    “Network”: {

    “Wait”: true,

    “Enabled”: false,

    “BufferSize”: 256

    },

    “Host”: {

    “Es2LibraryPath”: “”,

    “Es1LibraryPath”: “”,

    “EglLibraryPath”: “”,

    “Es3LibraryPath”: “”

    },

    “Process”: {

    “Exclude”: [

    “com.powervr.PVRHub”,

    "/system/bin/bootanimation",

    "/system/bin/surfaceflinger",

    “com.android.systemui”,

    “com.android.settings”,

    “system_server”,

    “com.google.android.googlequicksearchbox”

    ]

    },

    “Profiling”: {

    “SoftwareCounters”: true,

    “FunctionTimelineLevel”: 1,

    “Enabled”: false,

    “RenderstateOverride”: true

    }

    }


  6. There isn’t a pvrtrace.cfg in the /data/data/com.powervr.PVRHub/ directory nor in my app directory.



    Bonus info, full LogCat output up to the crash:

    05-09 10:22:09.278 8990 8990 Zygote Switching descriptor 33 to /dev/null

    05-09 10:22:09.282 8990 8990 Zygote Switching descriptor 9 to /dev/null

    05-09 10:22:09.317 8990 8990 dalvikvm Late-enabling CheckJNI

    05-09 10:22:09.368 8990 8990 dalvikvm Enabling JNI app bug workarounds for target SDK version 4…

    05-09 10:22:09.899 8990 8990 ActivityThread Application com.novasapiens.Bacchus is waiting for the debugger on port 8100…

    05-09 10:22:09.907 8990 8990 System.out Sending WAIT chunk

    05-09 10:22:12.024 8990 8996 dalvikvm Debugger is active

    05-09 10:22:12.176 8990 8990 System.out Debugger has connected

    05-09 10:22:12.188 8990 8990 System.out waiting for debugger to settle…

    05-09 10:22:12.395 8990 8990 System.out waiting for debugger to settle…

    05-09 10:22:12.598 8990 8990 System.out waiting for debugger to settle…

    05-09 10:22:12.798 8990 8990 System.out waiting for debugger to settle…

    05-09 10:22:13.001 8990 8990 System.out waiting for debugger to settle…

    05-09 10:22:13.102 8990 8996 dalvikvm Debugger has detached; object registry had 25 entries

    05-09 10:22:13.200 8990 8990 jdwp dvmJdwpLastDebuggerActivity: no active debugger

    05-09 10:22:13.200 8990 8990 System.out debugger detached?

    05-09 10:22:13.243 8990 8990 dalvikvm Trying to load lib /data/app-lib/com.novasapiens.Bacchus-1/libPVRTrace.so 0x41ad65a8

    05-09 10:22:13.508 8990 8990 dalvikvm Added shared lib /data/app-lib/com.novasapiens.Bacchus-1/libPVRTrace.so 0x41ad65a8

    05-09 10:22:13.508 8990 8990 dalvikvm No JNI_OnLoad found in /data/app-lib/com.novasapiens.Bacchus-1/libPVRTrace.so 0x41ad65a8, skipping init

    05-09 10:22:13.508 8990 8990 dalvikvm Trying to load lib /data/app-lib/com.novasapiens.Bacchus-1/libEGL_PVRTRACE.so 0x41ad65a8

    05-09 10:22:13.708 8990 8990 dalvikvm Added shared lib /data/app-lib/com.novasapiens.Bacchus-1/libEGL_PVRTRACE.so 0x41ad65a8

    05-09 10:22:13.708 8990 8990 dalvikvm No JNI_OnLoad found in /data/app-lib/com.novasapiens.Bacchus-1/libEGL_PVRTRACE.so 0x41ad65a8, skipping init

    05-09 10:22:13.708 8990 8990 dalvikvm Trying to load lib /data/app-lib/com.novasapiens.Bacchus-1/libGLESv2_PVRTRACE.so 0x41ad65a8

    05-09 10:22:13.938 8990 8990 dalvikvm Added shared lib /data/app-lib/com.novasapiens.Bacchus-1/libGLESv2_PVRTRACE.so 0x41ad65a8

    05-09 10:22:13.938 8990 8990 dalvikvm No JNI_OnLoad found in /data/app-lib/com.novasapiens.Bacchus-1/libGLESv2_PVRTRACE.so 0x41ad65a8, skipping init

    05-09 10:22:13.938 8990 8990 dalvikvm Trying to load lib /data/app-lib/com.novasapiens.Bacchus-1/libbacchus.so 0x41ad65a8

    05-09 10:22:14.274 8990 8990 dalvikvm Added shared lib /data/app-lib/com.novasapiens.Bacchus-1/libbacchus.so 0x41ad65a8

    05-09 10:22:14.274 8990 8990 dalvikvm No JNI_OnLoad found in /data/app-lib/com.novasapiens.Bacchus-1/libbacchus.so 0x41ad65a8, skipping init

    05-09 10:22:14.934 8990 9078 BacchusView creating OpenGL ES 2.0 context

    05-09 10:22:14.993 8990 8990 ActivityManager Timeline: Activity_idle id: android.os.BinderProxy@41ad27b0 time:152561745

    05-09 10:22:15.001 8990 9078 PVRTrace(I) Config file found: /data/data/com.powervr.PVRHub/pvrtraceconfig.json

    05-09 10:22:15.005 8990 9078 PVRTrace(I) Setting the default host paths to the Android shim as PVRTrace appears to be compiled in

    05-09 10:22:15.005 8990 9078 PVRTrace Setting EglLibraryPath default to ‘/system/lib/libEGL.so’.

    05-09 10:22:15.005 8990 9078 PVRTrace Setting Es1LibraryPath default to ‘/system/lib/libGLESv1_CM.so’.

    05-09 10:22:15.005 8990 9078 PVRTrace Setting Es2LibraryPath default to ‘/system/lib/libGLESv2.so’.

    05-09 10:22:15.005 8990 9078 PVRTrace(I) Processes excluded from recording: com.powervr.PVRHub

    05-09 10:22:15.005 8990 9078 PVRTrace(I) Opening trace file ‘/data/data/com.powervr.PVRHub/recordings/com.novasapiens.Bacchus.pvrt’ for record recording.

    05-09 10:22:15.008 8990 9078 PVRTrace(I) ‘/data/data/com.powervr.PVRHub/recordings/com.novasapiens.Bacchus.pvrt’ already exists so will be overwritten.

    05-09 10:22:15.012 8990 9078 PVRTrace(I) Recorder Version: 3.3@2850432

    05-09 10:22:15.012 8990 9078 PVRTrace(I) Loading host library '/system/lib/libGLESv2.so’

    05-09 10:22:15.012 8990 9078 PVRTrace(I) Host library ‘/system/lib/libGLESv2.so’ loaded

    05-09 10:22:15.020 8990 9078 android-main GL Version = OpenGL ES 2.0 build 1.8.GOOGLENEXUS.ED945322@2112805

    05-09 10:22:15.020 8990 9078 android-main GL Vendor = Imagination Technologies

    05-09 10:22:15.020 8990 9078 android-main GL Renderer = PowerVR SGX 540 + PVRTrace 3.3 (3.3@2850432)

    05-09 10:22:15.020 8990 9078 android-main GL Extensions = GL_EXT_debug_marker GL_OES_rgb8_rgba8 GL_OES_depth24 GL_OES_vertex_half_float GL_OES_texture_float GL_OES_texture_half_float GL_OES_element_index_uint GL_OES_mapbuffer GL_OES_fragment_precision_high GL_OES_compressed_ETC1_RGB8_texture GL_O



    And here is the contents of the .pvrt up to the crash

    NoCalls:16

    NoFrames:1



    Writing to file:



    Frame:1/1

ES2 glGetString(GL_VERSION) ==> OpenGL ES 2.0 build 1.8.GOOGLENEXUS.ED945322@2112805 Error: GL_NO_ERROR
ES2 glGetError() ==> GL_NO_ERROR Error: GL_NO_ERROR
ES2 glGetString(GL_VENDOR) ==> Imagination Technologies Error: GL_NO_ERROR
ES2 glGetError() ==> GL_NO_ERROR Error: GL_NO_ERROR
ES2 glGetString(GL_RENDERER) ==> PowerVR SGX 540 + PVRTrace 3.3 (3.3@2850432) Error: GL_NO_ERROR
ES2 glGetError() ==> GL_NO_ERROR Error: GL_NO_ERROR
ES2 glGetString(GL_EXTENSIONS) ==> GL_EXT_debug_marker GL_OES_rgb8_rgba8 GL_OES_depth24 GL_OES_vertex_half_float GL_OES_texture_float GL_OES_texture_half_float GL_OES_element_index_uint GL_OES_mapbuffer GL_OES_fragment_precision_high GL_OES_compressed_ETC1_RGB8_texture GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_required_internalformat GL_OES_depth_texture GL_OES_get_program_binary GL_OES_packed_depth_stencil GL_OES_standard_derivatives GL_OES_vertex_array_object GL_OES_egl_sync GL_EXT_multi_draw_arrays GL_EXT_texture_format_BGRA8888 GL_EXT_discard_framebuffer GL_EXT_shader_texture_lod GL_IMG_shader_binary GL_IMG_texture_compression_pvrtc GL_IMG_texture_npot GL_IMG_texture_format_BGRA8888 GL_IMG_read_format GL_IMG_program_binary GL_IMG_multisampled_render_to_texture Error: GL_NO_ERROR
ES2 glGetError() ==> GL_NO_ERROR Error: GL_NO_ERROR
ES2 glClearColor(1.000000,0.410000,0.710000,1.000000) Error: GL_NO_ERROR
ES2 glGetError() ==> GL_NO_ERROR Error: GL_NO_ERROR
ES2 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) Error: GL_NO_ERROR
ES2 glGetError() ==> GL_NO_ERROR Error: GL_NO_ERROR
ES2 glViewport(0,0,800,480) Error: GL_NO_ERROR
ES2 glGetError() ==> GL_NO_ERROR Error: GL_NO_ERROR
ES2 glGenTextures(1,70001) Error: GL_NO_ERROR
ES2 glGetError() ==> GL_NO_ERROR Error: GL_NO_ERROR

Hi,



Thanks for the information. We have some follow up questions:


  1. Are you using PVRHub to install the recorder libraries, or have you compiled them into your APK?

  2. We can't see any EGL calls in your logs. Have you removed them?

  3. Are you calling EGL from native, or from Java? There's a known limitation where we cannot record EGL calls from Java if the recorder libraries are built into your APK



Thanks,
Joe
  1. Compiled in to my APK. Somewhat related note, I wasn’t able to install the libs with PVRHub, my device is rooted and normally when an application requests root access I get a popup to confirm authorization but I don’t get one for PVRHub. PVRHub simply informs me it couldn’t get root access and I didn’t find a way to grant authorization without the app first making the request.

    2/3. The only EGL calls in the project are in Java, no particular reason, that’s just how the sample project I built off of worked.

Are you running SuperSU or a similar application on your device? PVRHub should cause a dialog to popup and confirm that you’re allowing the app to have root access. If this isn’t working, you should be able to configure application permissions within SuperSU. As an alternative, you can launch the PVRHubDaemon from a root terminal to enable PVRHub to execute commands as root. Here’s an ADB command for this:

adb shell su -c ‘/data/data/com.powervr.PVRHub/bin/PVRHubDaemon’&



As you’re using EGL through Java, you will have to use PVRHub to install the recorder libraries to the system. Alternatively, you can modify your application to issue all EGL calls from native, which will allow the APK recorder library packaging approach to work.



Cheers,

Joe

Cyanogenmod uses an app called Superuser, it is supposed to work as you described where when I run PVRHub I get a popup to confirm root access. A little research indicated that SuperSU will play nice with cyanogenmod so I installed that but same results, when I ran PVRHub I didn’t get a popup requesting access. I then tried running the Daemon and that worked (I had tried running it previously from the adb shell without success but that is likely due to my unfamiliarity with adb/linux). With the Daemon running PVRHub was able to install the libs and that seems to have solved my issue. My app now runs and it looks like I’m getting full trace logs :slight_smile:



Thanks for your help Joe!

No problem. Glad to hear the issue is solved :slight_smile:



Joe

Dear god. Now that the libs are installed the phone has become basically unusable. Is that normal? How do I uninstall the libs?

If the entire system feels sluggish, it may be the case that the recorder libraries are capturing every process (the splash screen, launcher etc.). On KitKat devices, this suggests that the config’s Exclude list is empty or missing system processes.



You can restore your device using PVRHubDaemon with this command:

adb shell su -c ‘/data/data/com.powervr.PVRHub/bin/PVRHubDaemon -r’


Thanks Joe, it was an issue with the exclusion list.

Just when I thought I was good…



I ran PVRHubDaemon -r to restore my device. It failed because it couldn’t find a .so. I then tried reinstalling the libs with PVRHub and now the phone is in an infinite boot cycle. Is there a way to manually restore the phone short of wiping it?

Did you run PVRHubDaemon from a root terminal session, or use the command I mentioned before to execute as root on the target with adb?



Appendix A of the PVRHub manual explains how the daemon works, what options are available and how it modifies the file system. As discussed there, you can execute the daemon with the ‘-g’ flag to generate a report of the system status.

adb shell su -c '/data/data/com.powervr.PVRHub/bin/PVRHubDaemon -g’

If you can send us this report (either through the forum or as a support ticket), we can help you investigate the cause of the problem. It may be the case that the Cyanogen file system is for some reason different than vanilla Android builds we’ve tested.