本地数字人频繁切换人物形象会导致应用崩溃
The cause of the problem is as follows: When switching models, the current code first releases the old instance, and then immediately creates a new model instance. In Duix, the release() method only sends a stop message to the rendering thread, without waiting for the thread to actually finish. The old thread only executes scrfdncnn.free(0) later. All digital human instances in the JNI layer share a global g_digit pointer. After the new model covers the global pointer, the old rendering thread may release the new instance; a subsequent call to dhduix_free(NULL) will crash, because the function directly accesses dg->running. The correct solution is as follows: Add the ability to “release and wait for completion” to the SDK: stop the old rendering thread, then execute join() to confirm that the thread has completely exited before creating a new model. Use a single-threaded queue or a mutex lock in DuixEmbeddedHost to strictly serialize the operations “stop voice → release old instance → wait for thread to exit → remove old view → create new instance”. Add a null pointer check and idempotent protection to the JNI’s free method, and clear the global pointer before releasing. A more thorough solution is to change the JNI’s global g_digit to a native handle that is independent of each instance, but this change would be more significant. The pressure test should switch at least 50 to 100 times in a row, covering the switching after the broadcast ends, the page exit, and the switching between the foreground and background of the application.
内容来源: duixcom/Duix-Mobile