Editor: Fix InspectorPanel AddComponent popup crash

- Remove SeparatorText which causes PopStyleVar mismatch in ImGui
- Add stderr redirection for better error capture
- Add debug logging to InspectorPanel
- Fix EditorLayer commented out undefined functions
This commit is contained in:
2026-03-25 12:56:51 +08:00
parent 0834ccb7aa
commit cad6f586fb
6 changed files with 70 additions and 88 deletions

View File

@@ -7,9 +7,28 @@
#include <imgui_impl_dx12.h>
#include <imgui_internal.h>
#include <stdio.h>
#include <windows.h>
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
static LONG WINAPI GlobalExceptionFilter(EXCEPTION_POINTERS* exceptionPointers) {
const char* logPath = "D:\\Xuanchi\\Main\\XCEngine\\editor\\bin\\Release\\crash.log";
FILE* f = fopen(logPath, "a");
if (f) {
fprintf(f, "[CRASH] ExceptionCode=0x%08X, Address=0x%p\n",
exceptionPointers->ExceptionRecord->ExceptionCode,
exceptionPointers->ExceptionRecord->ExceptionAddress);
fclose(f);
}
fprintf(stderr, "[CRASH] ExceptionCode=0x%08X, Address=0x%p\n",
exceptionPointers->ExceptionRecord->ExceptionCode,
exceptionPointers->ExceptionRecord->ExceptionAddress);
return EXCEPTION_EXECUTE_HANDLER;
}
namespace XCEngine {
namespace Editor {
@@ -19,6 +38,31 @@ Application& Application::Get() {
}
bool Application::Initialize(HWND hwnd) {
// Set global exception filter first to catch any crashes
SetUnhandledExceptionFilter(GlobalExceptionFilter);
// Redirect stderr to log file to capture ImGui errors
{
wchar_t exePath[MAX_PATH];
GetModuleFileNameW(nullptr, exePath, MAX_PATH);
std::wstring exeDirW(exePath);
size_t pos = exeDirW.find_last_of(L"\\/");
if (pos != std::wstring::npos) {
exeDirW = exeDirW.substr(0, pos);
}
std::string exeDir;
int len = WideCharToMultiByte(CP_UTF8, 0, exeDirW.c_str(), -1, nullptr, 0, nullptr, nullptr);
if (len > 0) {
exeDir.resize(len - 1);
WideCharToMultiByte(CP_UTF8, 0, exeDirW.c_str(), -1, &exeDir[0], len, nullptr, nullptr);
}
std::string stderrPath = exeDir + "\\stderr.log";
freopen(stderrPath.c_str(), "w", stderr);
fprintf(stderr, "[TEST] stderr redirection test - this should appear in stderr.log\n");
fflush(stderr);
}
// Initialize logging first
Debug::Logger::Get().AddSink(std::make_unique<Debug::ConsoleLogSink>());