整理卡死的问题

This commit is contained in:
xsl
2026-04-21 00:03:27 +08:00
parent 5d8e108306
commit 7ab4274e4f
9 changed files with 31 additions and 42 deletions
@@ -94,12 +94,12 @@ public class FaceActivity extends GameActivity implements FaceLandmarkerHelper.L
{ {
detectFace(image); detectFace(image);
} }
else // else
{ // {
image.close(); // image.close();
} // }
} finally { } finally {
//image.close(); // 确保在这里关闭 image.close(); // 确保在这里关闭
//Log.d("Camera", "Image closed, ready for next frame"); //Log.d("Camera", "Image closed, ready for next frame");
} }
} }
@@ -192,7 +192,7 @@ class FaceLandmarkerHelper(
Bitmap.Config.ARGB_8888 Bitmap.Config.ARGB_8888
) )
imageProxy.use { bitmapBuffer.copyPixelsFromBuffer(imageProxy.planes[0].buffer) } imageProxy.use { bitmapBuffer.copyPixelsFromBuffer(imageProxy.planes[0].buffer) }
imageProxy.close() //imageProxy.close()
val matrix = Matrix().apply { val matrix = Matrix().apply {
// Rotate the frame received from the camera to be in the same direction as it'll be shown // Rotate the frame received from the camera to be in the same direction as it'll be shown
+1 -1
View File
@@ -9,7 +9,7 @@ android {
compileSdk 36 compileSdk 36
defaultConfig { defaultConfig {
applicationId "com.inewme.uvmirror.f20251129" applicationId "com.inewme.uvmirror.f20260113"
minSdk 30 minSdk 30
targetSdk 36 targetSdk 36
versionCode 1 versionCode 1
@@ -8,7 +8,6 @@ import com.hmwl.face_sdk.Frame
import com.hmwl.face_sdk.InitArg import com.hmwl.face_sdk.InitArg
import com.hmwl.face_sdk.Motion import com.hmwl.face_sdk.Motion
import com.hmwl.face_sdk.MotionList import com.hmwl.face_sdk.MotionList
import org.checkerframework.checker.units.qual.radians
import org.json.JSONObject import org.json.JSONObject
import java.io.BufferedReader import java.io.BufferedReader
import java.io.InputStreamReader import java.io.InputStreamReader
+1 -1
View File
@@ -1,3 +1,3 @@
<resources> <resources>
<string name="app_name">f20251129</string> <string name="app_name">f20260113</string>
</resources> </resources>
+14 -17
View File
@@ -582,23 +582,20 @@ void Application::drawFrame(long long frameTime)
submitInfo.signalSemaphoreCount = 1; submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = signalSemaphores; submitInfo.pSignalSemaphores = signalSemaphores;
// graphicsQueue 与主线程 drawFrame、FaceApp::endSingleTimeCommandsJNI/worker 线程)共用,必须串行 if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]) != VK_SUCCESS) {
{ throw std::runtime_error("failed to submit draw command buffer!");
std::lock_guard<std::mutex> lock(mtx);
if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]) != VK_SUCCESS) {
throw std::runtime_error("failed to submit draw command buffer!");
}
// 7. 呈现图像
VkPresentInfoKHR presentInfo{};
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfo.waitSemaphoreCount = 1;
presentInfo.pWaitSemaphores = signalSemaphores;
VkSwapchainKHR swapChains[] = { swapChain };
presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = swapChains;
presentInfo.pImageIndices = &imageIndex;
result = vkQueuePresentKHR(presentQueue, &presentInfo);
} }
// 7. 呈现图像
VkPresentInfoKHR presentInfo{};
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfo.waitSemaphoreCount = 1;
presentInfo.pWaitSemaphores = signalSemaphores;
VkSwapchainKHR swapChains[] = { swapChain };
presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = swapChains;
presentInfo.pImageIndices = &imageIndex;
result = vkQueuePresentKHR(presentQueue, &presentInfo);
if (result != VK_SUCCESS) { if (result != VK_SUCCESS) {
throw std::runtime_error("failed to present swap chain image!"); throw std::runtime_error("failed to present swap chain image!");
} }
@@ -854,7 +851,7 @@ void Application::createTexture(VkDevice device, VkPhysicalDevice physicalDevice
void Application::processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& texture, bool srgb, VkCommandPool pool, std::string tex_path) void Application::processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& texture, bool srgb, VkCommandPool pool, std::string tex_path)
{ {
std::unique_lock<std::mutex> lock(mtx); std::unique_lock<std::mutex> lock(createTextureMtx);
if (texture.image == VK_NULL_HANDLE) if (texture.image == VK_NULL_HANDLE)
{ {
createTexture(device, physicalDevice, width, height, texture, srgb, tex_path, dataSize); createTexture(device, physicalDevice, width, height, texture, srgb, tex_path, dataSize);
+2 -5
View File
@@ -47,7 +47,7 @@ public:
virtual void drawFrame(long long frameTime); virtual void drawFrame(long long frameTime);
virtual void render(VkCommandBuffer commandBuffer, long long frameTime); virtual void render(VkCommandBuffer commandBuffer, long long frameTime);
virtual bool isInited() { return _applicationInited; } virtual bool isInited() { return _applicationInited; }
std::mutex createTextureMtx;
void processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& texture, bool srgb, VkCommandPool pool, std::string tex_path); void processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& texture, bool srgb, VkCommandPool pool, std::string tex_path);
protected: protected:
@@ -96,10 +96,7 @@ protected:
void endSingleTimeCommands(VkDevice device, VkCommandPool commandPool, VkQueue queue, VkCommandBuffer commandBuffer); void endSingleTimeCommands(VkDevice device, VkCommandPool commandPool, VkQueue queue, VkCommandBuffer commandBuffer);
void transitionImageLayout(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout oldLayout, VkImageLayout newLayout); void transitionImageLayout(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout oldLayout, VkImageLayout newLayout);
void destroy_texture(Texture texture); void destroy_texture(Texture texture);
std::mutex mtx;
long long _lastDrawFrameTime; long long _lastDrawFrameTime;
std::mutex changeMotionMtx;
}; };
+6 -11
View File
@@ -683,10 +683,6 @@ void FaceApp::update_descriptor_set(vector<Texture>& texs, vector<VkDescriptorSe
void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime) void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime)
{ {
std::unique_lock<std::mutex> lock(mtx);
std::unique_lock<std::mutex> lock_point(mtx_point);
std::unique_lock<std::mutex> lock_changeMotion(changeMotionMtx);
//Application::render(commandBuffer); //Application::render(commandBuffer);
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout_bg, 0, 1, &m_descriptor_set_bg, 0, NULL); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout_bg, 0, 1, &m_descriptor_set_bg, 0, NULL);
@@ -984,12 +980,8 @@ void FaceApp::endSingleTimeCommands(VkCommandBuffer commandBuffer) {
submitInfo.commandBufferCount = 1; submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &commandBuffer; submitInfo.pCommandBuffers = &commandBuffer;
// 与 Application::drawFrame 共用 graphicsQueue,必须串行,避免驱动内 SIGSEGV vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);
{ vkQueueWaitIdle(graphicsQueue);
std::lock_guard<std::mutex> lock(mtx);
vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);
vkQueueWaitIdle(graphicsQueue);
}
vkFreeCommandBuffers(device, commandPool, 1, &commandBuffer); vkFreeCommandBuffers(device, commandPool, 1, &commandBuffer);
} }
@@ -1460,7 +1452,9 @@ void FaceApp::drawFrame(long long frameTime)
game_time = game_time - actionTime; game_time = game_time - actionTime;
} }
} }
std::unique_lock<std::mutex> lock_point(mtx_point);
std::unique_lock<std::mutex> lock_changeMotion(changeMotionMtx);
std::unique_lock<std::mutex> lock_Texture(createTextureMtx);
Application::drawFrame(frameTime); Application::drawFrame(frameTime);
} }
@@ -1620,3 +1614,4 @@ void FaceApp::StopMotion() {
void FaceApp::ResumeMotion() { void FaceApp::ResumeMotion() {
_playMotion = true; _playMotion = true;
} }
+1
View File
@@ -153,6 +153,7 @@ private:
std::map<int, int> vertices_map_3dmax; std::map<int, int> vertices_map_3dmax;
std::mutex mtx_point; std::mutex mtx_point;
std::mutex changeMotionMtx;
long long last_update_time; long long last_update_time;
VkBuffer uniform_buffer_vs; VkBuffer uniform_buffer_vs;