fix bug and add log

This commit is contained in:
xsl
2026-04-23 22:18:22 +08:00
parent fb434f09b8
commit 27b7075818
7 changed files with 327 additions and 40 deletions
+71 -1
View File
@@ -32,11 +32,14 @@ FaceApp::~FaceApp()
void FaceApp::Stop()
{
FACE_DBG_LOG("FaceApp::Stop called (_running=%d worker_joinable=%d)",
(int)_running, (int)worker_.joinable());
_running = false;
if(worker_.joinable())
{
worker_.join();
}
FACE_DBG_LOG("FaceApp::Stop done");
}
void ReceiveFacePoint(float* pos, int pointCount, int width, int height)
@@ -858,14 +861,70 @@ void FaceApp::initVulkan()
void FaceApp::clearnSecondFaceApp()
{
FACE_DBG_LOG("FaceApp::clearnSecondFaceApp: _secondfaceAppInited %d -> 0",
(int)_secondfaceAppInited);
_secondfaceAppInited = false;
}
void FaceApp::Start()
{
FACE_DBG_LOG("FaceApp::Start: _running %d -> 1", (int)_running);
_running = true;
}
void FaceApp::onWindowLost()
{
FACE_DBG_LOG("FaceApp::onWindowLost enter _applicationInited=%d _faceAppInited=%d _sceondInited=%d _secondfaceAppInited=%d _running=%d",
(int)_applicationInited, (int)_faceAppInited, (int)_sceondInited,
(int)_secondfaceAppInited, (int)_running);
// Stop the render loop from touching Vulkan while we tear down.
_running = false;
// Serialize against JNI callbacks that may concurrently submit GPU work
// via commandPool / commandPool_ex (processImageNative -> update texture,
// passDataToNative -> update vertex buffer, changeMotionList).
std::unique_lock<std::mutex> lk_point(mtx_point);
std::unique_lock<std::mutex> lk_motion(changeMotionMtx);
std::unique_lock<std::mutex> lk_tex(createTextureMtx);
Application::cleanupForWindowLost();
_secondfaceAppInited = false;
FACE_DBG_LOG("FaceApp::onWindowLost done");
}
void FaceApp::onWindowInit()
{
FACE_DBG_LOG("FaceApp::onWindowInit enter _applicationInited=%d _faceAppInited=%d _sceondInited=%d _secondfaceAppInited=%d",
(int)_applicationInited, (int)_faceAppInited, (int)_sceondInited,
(int)_secondfaceAppInited);
if (!_applicationInited) {
// First-time path: go through the full initVulkan pipeline.
initVulkan();
} else {
// Recovery path after an earlier onWindowLost. Rebuild only the
// window-dependent Vulkan objects; keep renderPass / pipelines /
// FaceApp GPU resources intact.
std::unique_lock<std::mutex> lk_point(mtx_point);
std::unique_lock<std::mutex> lk_motion(changeMotionMtx);
std::unique_lock<std::mutex> lk_tex(createTextureMtx);
Application::reinitForNewWindow();
if (!_secondfaceAppInited) {
_secondfaceAppInited = true;
_playMotion = true;
_running = true;
}
}
FACE_DBG_LOG("FaceApp::onWindowInit done _applicationInited=%d _faceAppInited=%d _sceondInited=%d _secondfaceAppInited=%d _running=%d",
(int)_applicationInited, (int)_faceAppInited, (int)_sceondInited,
(int)_secondfaceAppInited, (int)_running);
}
void FaceApp::update_uniform_buffers()
{
uint32_t width = 480;
@@ -1340,6 +1399,7 @@ void FaceApp::cleanupResources(VkDevice device, VmaAllocator allocator) {
void FaceApp::cleanup()
{
FACE_DBG_LOG("FaceApp::cleanup enter");
vkDeviceWaitIdle(device);
if (uniform_buffer_mapped != nullptr)
@@ -1375,7 +1435,7 @@ void FaceApp::cleanup()
// allocator = VK_NULL_HANDLE;
//}
FACE_DBG_LOG("FaceApp::cleanup done");
}
@@ -1481,6 +1541,8 @@ void FaceApp::drawFrame(long long frameTime)
string FaceApp::preLoadMotionList(string motion_list_str, Callback callback)
{
FACE_DBG_LOG("FaceApp::preLoadMotionList called str_len=%zu _isLoadMotion=%d",
motion_list_str.size(), (int)_isLoadMotion);
if (_isLoadMotion)
{
return "failue load not finished";
@@ -1496,11 +1558,13 @@ string FaceApp::preLoadMotionList(string motion_list_str, Callback callback)
worker_.join();
}
worker_ = std::thread(&FaceApp::loadMotionThread, this);
FACE_DBG_LOG("FaceApp::preLoadMotionList worker_ started, todo_count=%zu", _curLoadMotionList.size());
return "ok";
}
void FaceApp::loadMotionThread()
{
FACE_DBG_LOG("FaceApp::loadMotionThread enter, todo_count=%zu", _curLoadMotionList.size());
while (!isInited())
{
std::this_thread::sleep_for(std::chrono::milliseconds(50));
@@ -1561,6 +1625,7 @@ void FaceApp::loadMotionThread()
// }
update_descriptor_set(m_texs_left, m_descriptor_sets_left);
_isLoadMotion = false;
FACE_DBG_LOG("FaceApp::loadMotionThread done, loaded_total=%zu", motion_list_map.size());
_callback_loadfinish();
}
@@ -1572,6 +1637,9 @@ Motion FaceApp::getMotionByName(string name)
void FaceApp::changeMotionList(vector<string> motions, AnimationFinishedCallback callback, bool loop)
{
DebugLog::log_throttled("FaceApp.changeMotionList",
"FaceApp::changeMotionList called count=%zu loop=%d _isLoadMotion=%d",
motions.size(), (int)loop, (int)_isLoadMotion);
if (_isLoadMotion)
{
return;
@@ -1623,10 +1691,12 @@ void FaceApp::changeMotionList(vector<string> motions, AnimationFinishedCallback
}
void FaceApp::StopMotion() {
FACE_DBG_LOG("FaceApp::StopMotion: _playMotion %d -> 0", (int)_playMotion);
_playMotion = false;
}
void FaceApp::ResumeMotion() {
FACE_DBG_LOG("FaceApp::ResumeMotion: _playMotion %d -> 1", (int)_playMotion);
_playMotion = true;
}