I seem to have solved this error. Indeed, the code in my original post is the correct way to switch textures during run-time (this has been confirmed by the admins on the Vuforia forums).
The problem was a threading issue. I had retrieved code for the GUIManager
class from the Dominoes sample application to add buttons and other elements to the screen. That class uses a Handler
to receive messages and then perform appropriate GUI-related tasks.
The problem is that you have to ensure initApplicationNative()
is called on the Main thread, while mRenderer.initRendering()
is called on the GLThread. Not only that, but if the array of textures is changing at any point between the initApplicationNative()
call and the mRenderer.initRendering()
calls, it can cause a failure in the native code (there are some assert()
calls).
There is some more information about Threading in Vuforia here: https://developer.vuforia.com/forum/faq/android-which-methods-are-called-ui-vs-opengl-thread
I believe that there were timing issues, as well as sometimes functions were called on the wrong thread. To make my program work, I removed the Handlers from FrameMarkers.java
and GUIManager.java
, and called all of my texture-updating code from the Main thread.
This ensures that deinitApplicationNative()
and initApplicationNative()
are always called from the Main thread, whereas mGlView.queueEvent()
ensures that the GL code runs on that thread.