From 0834ccb7aad800bc2ce7ee23b2acf5e5936f9244 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Wed, 25 Mar 2026 12:30:35 +0800 Subject: [PATCH] Editor: Add crash exception filter to InspectorPanel AddComponent - Add Windows structured exception handling to catch crashes during component addition - Log crashes to file and stderr for debugging --- editor/src/panels/InspectorPanel.cpp | 30 ++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/editor/src/panels/InspectorPanel.cpp b/editor/src/panels/InspectorPanel.cpp index 3caeea48..07ad07bd 100644 --- a/editor/src/panels/InspectorPanel.cpp +++ b/editor/src/panels/InspectorPanel.cpp @@ -5,6 +5,24 @@ #include #include #include +#include +#include + +static LONG WINAPI CrashExceptionFilter(EXCEPTION_POINTERS* exceptionPointers) { + char buffer[1024]; + std::snprintf(buffer, sizeof(buffer), + "[CRASH] ExceptionCode=0x%08X, Address=0x%p", + exceptionPointers->ExceptionRecord->ExceptionCode, + exceptionPointers->ExceptionRecord->ExceptionAddress); + + FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\editor\\bin\\Release\\crash.log", "a"); + if (f) { + fprintf(f, "%s\n", buffer); + fclose(f); + } + fprintf(stderr, "%s\n", buffer); + return EXCEPTION_EXECUTE_HANDLER; +} namespace XCEngine { namespace Editor { @@ -85,8 +103,16 @@ void InspectorPanel::RenderAddComponentPopup(::XCEngine::Components::GameObject* Debug::Logger::Get().Debug(Debug::LogCategory::General, "About to check MenuItem condition"); if (ImGui::MenuItem("Transform", nullptr, false, !hasTransform)) { Debug::Logger::Get().Debug(Debug::LogCategory::General, "MenuItem CLICKED! Before AddComponent"); - auto* newComp = gameObject->AddComponent<::XCEngine::Components::TransformComponent>(); - Debug::Logger::Get().Debug(Debug::LogCategory::General, newComp ? "AddComponent SUCCEEDED" : "AddComponent FAILED"); + + void* newComp = nullptr; + __try { + newComp = gameObject->AddComponent<::XCEngine::Components::TransformComponent>(); + Debug::Logger::Get().Debug(Debug::LogCategory::General, newComp ? "AddComponent SUCCEEDED" : "AddComponent FAILED"); + } + __except(CrashExceptionFilter(GetExceptionInformation())) { + Debug::Logger::Get().Error(Debug::LogCategory::General, "AddComponent CRASHED!"); + } + ImGui::CloseCurrentPopup(); } else { Debug::Logger::Get().Debug(Debug::LogCategory::General, "MenuItem not clicked (disabled or condition false)");