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
This commit is contained in:
2026-03-25 12:30:35 +08:00
parent 0948e0fdbe
commit 0834ccb7aa

View File

@@ -5,6 +5,24 @@
#include <XCEngine/Debug/Logger.h>
#include <imgui.h>
#include <string>
#include <windows.h>
#include <excpt.h>
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)");