diff --git a/MFCCreoDll.cpp b/MFCCreoDll.cpp index 5ee4eab..3d4d21d 100644 --- a/MFCCreoDll.cpp +++ b/MFCCreoDll.cpp @@ -31,13 +31,14 @@ static UINT_PTR timer_id = 0; // 无锁消息队列项 struct MessageItem { - std::string type; // "SHOW_MESSAGE", "OPEN_MODEL_REQUEST", 或 "SHRINKWRAP_SHELL_REQUEST" + std::string type; // "SHOW_MESSAGE", "OPEN_MODEL_REQUEST", "SHRINKWRAP_SHELL_REQUEST", 或 "TIMEOUT_CLEANUP" std::string data; // 消息内容或文件路径或JSON数据 std::string extra; // 额外参数(如open_mode) volatile bool completed; // 完成标志 + volatile bool timed_out; // 超时标志,用于指示HTTP请求已超时返回 void* result_ptr; // 结果指针 - MessageItem() : completed(false), result_ptr(nullptr) {} + MessageItem() : completed(false), timed_out(false), result_ptr(nullptr) {} }; // 无锁同步机制 @@ -123,6 +124,15 @@ VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) // 执行Shrinkwrap处理 HttpResponse response = ShellExportHandler::HandleShrinkwrapShellRequest(shrinkwrap_request); + // 检查是否已超时,若超时则清理内存并跳过 + if (item->timed_out) { + // HTTP请求已超时返回,清理堆分配的MessageItem + delete item; + pending_message_item = nullptr; + has_pending_item = false; + return; // 直接返回,不设置completed + } + // 保存结果 item->result_ptr = new HttpResponse(response); item->completed = true; @@ -1624,7 +1634,7 @@ HttpResponse ShrinkwrapShellHandler(const HttpRequest& request) { try { // 解析请求获取超时参数 - int timeout_seconds = 30; // 默认值 + int timeout_seconds = 60; // 默认值改为60秒 try { // 简单解析JSON获取timeout_seconds std::string json_body = request.body; @@ -1639,33 +1649,37 @@ HttpResponse ShrinkwrapShellHandler(const HttpRequest& request) { } } catch (...) { // 解析失败,使用默认值 - timeout_seconds = 30; + timeout_seconds = 60; } - // 使用无锁消息机制 - MessageItem shrinkwrap_message_item; - shrinkwrap_message_item.type = "SHRINKWRAP_SHELL_REQUEST"; - shrinkwrap_message_item.data = request.body; + // 使用堆分配的MessageItem,避免超时后悬空指针问题 + MessageItem* shrinkwrap_message_item = new MessageItem(); + shrinkwrap_message_item->type = "SHRINKWRAP_SHELL_REQUEST"; + shrinkwrap_message_item->data = request.body; // 原子设置(无锁) - pending_message_item = &shrinkwrap_message_item; + pending_message_item = shrinkwrap_message_item; has_pending_item = true; // 等待主线程完成操作(带动态超时) int timeout_ms = timeout_seconds * 1000; // 转换为毫秒 - while (!shrinkwrap_message_item.completed && timeout_ms > 0) { + while (!shrinkwrap_message_item->completed && timeout_ms > 0) { Sleep(100); // 稍长的间隔,因为Shrinkwrap是重操作 timeout_ms -= 100; } - if (shrinkwrap_message_item.completed && shrinkwrap_message_item.result_ptr) { - HttpResponse result = *static_cast(shrinkwrap_message_item.result_ptr); - delete static_cast(shrinkwrap_message_item.result_ptr); // 清理内存 + if (shrinkwrap_message_item->completed && shrinkwrap_message_item->result_ptr) { + // 操作成功完成 + HttpResponse result = *static_cast(shrinkwrap_message_item->result_ptr); + delete static_cast(shrinkwrap_message_item->result_ptr); // 清理结果内存 + delete shrinkwrap_message_item; // 清理MessageItem内存 return result; } else { - // 超时处理 + // 超时处理:标记为已超时,让TimerProc负责清理 + shrinkwrap_message_item->timed_out = true; response.status_code = 504; - response.body = "{\"success\": false, \"error\": \"Operation timeout: Shrinkwrap export exceeded " + std::to_string(timeout_seconds) + " seconds limit\"}"; + response.body = "{\"success\": false, \"error\": \"Operation timeout: Shrinkwrap export exceeded " + + std::to_string(timeout_seconds) + " seconds limit\", \"note\": \"The Creo operation may still complete in background. Check Creo for results.\"}"; return response; } diff --git a/MFCCreoDll.vcxproj b/MFCCreoDll.vcxproj index e971379..405f740 100644 --- a/MFCCreoDll.vcxproj +++ b/MFCCreoDll.vcxproj @@ -96,6 +96,7 @@ _WINDOWS;_USRDLL;USE_ANSI_IOSTREAMS;PRO_USE_VAR_ARGS;PRO_MACHINE=36;HYCOMMONWINAPI_EXPORTS;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) pch.h MultiThreadedDLL + ProgramDatabase Windows diff --git a/MFCCreoDll/x64/Debug/AuthManager.obj b/MFCCreoDll/x64/Debug/AuthManager.obj index c61f49a..28c4ecc 100644 Binary files a/MFCCreoDll/x64/Debug/AuthManager.obj and b/MFCCreoDll/x64/Debug/AuthManager.obj differ diff --git a/MFCCreoDll/x64/Debug/BatchOperationManager.obj b/MFCCreoDll/x64/Debug/BatchOperationManager.obj index 8b787ae..f3264d9 100644 Binary files a/MFCCreoDll/x64/Debug/BatchOperationManager.obj and b/MFCCreoDll/x64/Debug/BatchOperationManager.obj differ diff --git a/MFCCreoDll/x64/Debug/CodeAnalysisResultManifest.txt b/MFCCreoDll/x64/Debug/CodeAnalysisResultManifest.txt deleted file mode 100644 index 06a9a80..0000000 Binary files a/MFCCreoDll/x64/Debug/CodeAnalysisResultManifest.txt and /dev/null differ diff --git a/MFCCreoDll/x64/Debug/ComponentChildrenManager.obj b/MFCCreoDll/x64/Debug/ComponentChildrenManager.obj index 6e43620..c2e2914 100644 Binary files a/MFCCreoDll/x64/Debug/ComponentChildrenManager.obj and b/MFCCreoDll/x64/Debug/ComponentChildrenManager.obj differ diff --git a/MFCCreoDll/x64/Debug/CreoManager.obj b/MFCCreoDll/x64/Debug/CreoManager.obj index 6beeb92..a1b192a 100644 Binary files a/MFCCreoDll/x64/Debug/CreoManager.obj and b/MFCCreoDll/x64/Debug/CreoManager.obj differ diff --git a/MFCCreoDll/x64/Debug/CreoUtilities.obj b/MFCCreoDll/x64/Debug/CreoUtilities.obj index a1ac9c9..c5e5cab 100644 Binary files a/MFCCreoDll/x64/Debug/CreoUtilities.obj and b/MFCCreoDll/x64/Debug/CreoUtilities.obj differ diff --git a/MFCCreoDll/x64/Debug/GeometryAnalyzer.obj b/MFCCreoDll/x64/Debug/GeometryAnalyzer.obj index 8347005..948d96f 100644 Binary files a/MFCCreoDll/x64/Debug/GeometryAnalyzer.obj and b/MFCCreoDll/x64/Debug/GeometryAnalyzer.obj differ diff --git a/MFCCreoDll/x64/Debug/HierarchyStatisticsAnalyzer.obj b/MFCCreoDll/x64/Debug/HierarchyStatisticsAnalyzer.obj index 8cc1e21..e7e3b6c 100644 Binary files a/MFCCreoDll/x64/Debug/HierarchyStatisticsAnalyzer.obj and b/MFCCreoDll/x64/Debug/HierarchyStatisticsAnalyzer.obj differ diff --git a/MFCCreoDll/x64/Debug/HttpRouter.obj b/MFCCreoDll/x64/Debug/HttpRouter.obj index 11f78e9..b2a6fa0 100644 Binary files a/MFCCreoDll/x64/Debug/HttpRouter.obj and b/MFCCreoDll/x64/Debug/HttpRouter.obj differ diff --git a/MFCCreoDll/x64/Debug/HttpServer.obj b/MFCCreoDll/x64/Debug/HttpServer.obj index 068a9b4..2e6b7f3 100644 Binary files a/MFCCreoDll/x64/Debug/HttpServer.obj and b/MFCCreoDll/x64/Debug/HttpServer.obj differ diff --git a/MFCCreoDll/x64/Debug/JsonHelper.obj b/MFCCreoDll/x64/Debug/JsonHelper.obj index f23c8e6..737d35d 100644 Binary files a/MFCCreoDll/x64/Debug/JsonHelper.obj and b/MFCCreoDll/x64/Debug/JsonHelper.obj differ diff --git a/MFCCreoDll/x64/Debug/Logger.obj b/MFCCreoDll/x64/Debug/Logger.obj index c1d123d..d66dc31 100644 Binary files a/MFCCreoDll/x64/Debug/Logger.obj and b/MFCCreoDll/x64/Debug/Logger.obj differ diff --git a/MFCCreoDll/x64/Debug/MFCCreoDll.obj b/MFCCreoDll/x64/Debug/MFCCreoDll.obj index 53d331e..7c7eec8 100644 Binary files a/MFCCreoDll/x64/Debug/MFCCreoDll.obj and b/MFCCreoDll/x64/Debug/MFCCreoDll.obj differ diff --git a/MFCCreoDll/x64/Debug/MFCCreoDll.pch b/MFCCreoDll/x64/Debug/MFCCreoDll.pch index 3aa20b8..1db1d77 100644 Binary files a/MFCCreoDll/x64/Debug/MFCCreoDll.pch and b/MFCCreoDll/x64/Debug/MFCCreoDll.pch differ diff --git a/MFCCreoDll/x64/Debug/MFCCreoDll.tlog/CL.command.1.tlog b/MFCCreoDll/x64/Debug/MFCCreoDll.tlog/CL.command.1.tlog index 7fdd2a2..4a3fe9a 100644 Binary files a/MFCCreoDll/x64/Debug/MFCCreoDll.tlog/CL.command.1.tlog and b/MFCCreoDll/x64/Debug/MFCCreoDll.tlog/CL.command.1.tlog differ diff --git a/MFCCreoDll/x64/Debug/MFCCreoDll.tlog/CL.write.1.tlog b/MFCCreoDll/x64/Debug/MFCCreoDll.tlog/CL.write.1.tlog index 3c182ca..f379b1d 100644 Binary files a/MFCCreoDll/x64/Debug/MFCCreoDll.tlog/CL.write.1.tlog and b/MFCCreoDll/x64/Debug/MFCCreoDll.tlog/CL.write.1.tlog differ diff --git a/MFCCreoDll/x64/Debug/ModelAnalyzer.obj b/MFCCreoDll/x64/Debug/ModelAnalyzer.obj index 65a68f2..4983ed2 100644 Binary files a/MFCCreoDll/x64/Debug/ModelAnalyzer.obj and b/MFCCreoDll/x64/Debug/ModelAnalyzer.obj differ diff --git a/MFCCreoDll/x64/Debug/ModelSearchEngine.obj b/MFCCreoDll/x64/Debug/ModelSearchEngine.obj index 17f0611..c50de9a 100644 Binary files a/MFCCreoDll/x64/Debug/ModelSearchEngine.obj and b/MFCCreoDll/x64/Debug/ModelSearchEngine.obj differ diff --git a/MFCCreoDll/x64/Debug/ModelSearchHandler.obj b/MFCCreoDll/x64/Debug/ModelSearchHandler.obj index d343120..ce4cd93 100644 Binary files a/MFCCreoDll/x64/Debug/ModelSearchHandler.obj and b/MFCCreoDll/x64/Debug/ModelSearchHandler.obj differ diff --git a/MFCCreoDll/x64/Debug/PathDeleteManager.obj b/MFCCreoDll/x64/Debug/PathDeleteManager.obj index 63a626c..93aa633 100644 Binary files a/MFCCreoDll/x64/Debug/PathDeleteManager.obj and b/MFCCreoDll/x64/Debug/PathDeleteManager.obj differ diff --git a/MFCCreoDll/x64/Debug/ServerManager.obj b/MFCCreoDll/x64/Debug/ServerManager.obj index 8219189..185d0d0 100644 Binary files a/MFCCreoDll/x64/Debug/ServerManager.obj and b/MFCCreoDll/x64/Debug/ServerManager.obj differ diff --git a/MFCCreoDll/x64/Debug/ShellExportHandler.obj b/MFCCreoDll/x64/Debug/ShellExportHandler.obj index 71bdc0e..f25121f 100644 Binary files a/MFCCreoDll/x64/Debug/ShellExportHandler.obj and b/MFCCreoDll/x64/Debug/ShellExportHandler.obj differ diff --git a/MFCCreoDll/x64/Debug/ShrinkwrapManager.obj b/MFCCreoDll/x64/Debug/ShrinkwrapManager.obj index 29c7ae2..574e86b 100644 Binary files a/MFCCreoDll/x64/Debug/ShrinkwrapManager.obj and b/MFCCreoDll/x64/Debug/ShrinkwrapManager.obj differ diff --git a/MFCCreoDll/x64/Debug/WebSocketServer.obj b/MFCCreoDll/x64/Debug/WebSocketServer.obj index f10c1d2..18ca1e6 100644 Binary files a/MFCCreoDll/x64/Debug/WebSocketServer.obj and b/MFCCreoDll/x64/Debug/WebSocketServer.obj differ diff --git a/MFCCreoDll/x64/Debug/pch.obj b/MFCCreoDll/x64/Debug/pch.obj index dfab2dd..aa67419 100644 Binary files a/MFCCreoDll/x64/Debug/pch.obj and b/MFCCreoDll/x64/Debug/pch.obj differ diff --git a/MFCCreoDll/x64/Debug/vc143.idb b/MFCCreoDll/x64/Debug/vc143.idb deleted file mode 100644 index b35be2f..0000000 Binary files a/MFCCreoDll/x64/Debug/vc143.idb and /dev/null differ diff --git a/MFCCreoDll/x64/Debug/vc143.pdb b/MFCCreoDll/x64/Debug/vc143.pdb index b16c86c..458a649 100644 Binary files a/MFCCreoDll/x64/Debug/vc143.pdb and b/MFCCreoDll/x64/Debug/vc143.pdb differ diff --git a/ShrinkwrapManager.h b/ShrinkwrapManager.h index c4e467e..340c24c 100644 --- a/ShrinkwrapManager.h +++ b/ShrinkwrapManager.h @@ -23,18 +23,18 @@ struct ShrinkwrapShellRequest { std::string project_name = "Shrinkwrap Shell Export"; std::string method = "outer_shell"; std::string component_path = ""; // 可选:子装配体路径,如 "TopAsm.asm/SubAsm.asm",为空则使用当前模型 - int quality = 8; // 1-10, 质量等级 + int quality = 5; // 1-10, 质量等级(降低默认值避免大模型卡死) double chord_height = 0.1; // 弦高控制三角化误差(mm), 0.05-0.2 - bool fill_holes = true; // 自动填孔 - bool ignore_small_surfaces = true; // 忽略小表面 - double small_surface_percentage = 0.5; // 小表面百分比阈值 + bool fill_holes = false; // 自动填孔(关闭以提高稳定性) + bool ignore_small_surfaces = false; // 忽略小表面(关闭避免卡死) + double small_surface_percentage = 0.0; // 小表面百分比阈值(设为0不过滤) std::string output_file_path; // 输出文件路径 std::string output_type = "solid_surface"; // "solid_surface" or "facet" bool ignore_quilts = true; // 忽略面片 bool ignore_skeleton = true; // 忽略骨架 bool assign_mass_properties = false; // 分配质量属性 std::string preset = ""; // "fast", "balanced", "tight" or "" - int timeout_seconds = 30; // 超时时间(秒), 默认30秒,最大300秒 + int timeout_seconds = 60; // 超时时间(秒), 默认60秒,最大300秒 }; struct ShrinkwrapShellParameters { diff --git a/x64/Debug/MFCCreoDll.dll b/x64/Debug/MFCCreoDll.dll index bd06d44..e6de99d 100644 Binary files a/x64/Debug/MFCCreoDll.dll and b/x64/Debug/MFCCreoDll.dll differ diff --git a/x64/Debug/MFCCreoDll.pdb b/x64/Debug/MFCCreoDll.pdb index d62e4d5..0f000db 100644 Binary files a/x64/Debug/MFCCreoDll.pdb and b/x64/Debug/MFCCreoDll.pdb differ