remove windows debug code (for now...)

This commit is contained in:
2026-01-12 23:12:04 -05:00
parent 6cac267998
commit 945fd31735

View File

@@ -9,13 +9,6 @@
#include <SDL3_mixer/SDL_mixer.h> #include <SDL3_mixer/SDL_mixer.h>
#ifdef _WIN32
#include "util/path_.h"
#include <DbgHelp.h>
#include <format>
#include <windows.h>
#endif
#include "log.h" #include "log.h"
#include "sdl.h" #include "sdl.h"
@@ -44,117 +37,42 @@ namespace anm2ed
constexpr int SOCKET_ERROR_ADDRESS_IN_USE = EADDRINUSE; constexpr int SOCKET_ERROR_ADDRESS_IN_USE = EADDRINUSE;
#endif #endif
namespace bool socket_paths_send(Socket& socket, const std::vector<std::string>& paths)
{ {
#ifdef _WIN32 uint32_t count = htonl(static_cast<uint32_t>(paths.size()));
std::filesystem::path g_minidump_dir{}; if (!socket.send(&count, sizeof(count))) return false;
PVOID g_vectored_handler{};
LONG g_dump_in_progress{};
void windows_minidump_write(EXCEPTION_POINTERS* exceptionPointers) for (const auto& path : paths)
{ {
if (g_minidump_dir.empty()) return; uint32_t length = htonl(static_cast<uint32_t>(path.size()));
if (InterlockedExchange(&g_dump_in_progress, 1) != 0) return; if (!socket.send(&length, sizeof(length))) return false;
if (!path.empty() && !socket.send(path.data(), path.size())) return false;
SYSTEMTIME st{};
GetLocalTime(&st);
auto pid = GetCurrentProcessId();
auto code = exceptionPointers && exceptionPointers->ExceptionRecord
? exceptionPointers->ExceptionRecord->ExceptionCode
: 0u;
auto filename = std::format("anm2ed_{:04}{:02}{:02}_{:02}{:02}{:02}_pid{:08x}_code{:08x}.dmp", st.wYear,
st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, pid, code);
auto dumpPath = g_minidump_dir / path::from_utf8(filename);
auto dumpPathW = dumpPath.wstring();
HANDLE file = CreateFileW(dumpPathW.c_str(), GENERIC_WRITE, FILE_SHARE_READ, nullptr, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, nullptr);
if (file == INVALID_HANDLE_VALUE) return;
MINIDUMP_EXCEPTION_INFORMATION mei{};
mei.ThreadId = GetCurrentThreadId();
mei.ExceptionPointers = exceptionPointers;
mei.ClientPointers = FALSE;
const MINIDUMP_TYPE dumpType =
static_cast<MINIDUMP_TYPE>(MiniDumpNormal | MiniDumpWithIndirectlyReferencedMemory | MiniDumpWithThreadInfo |
MiniDumpWithUnloadedModules);
MiniDumpWriteDump(GetCurrentProcess(), pid, file, dumpType, exceptionPointers ? &mei : nullptr, nullptr, nullptr);
FlushFileBuffers(file);
CloseHandle(file);
} }
LONG WINAPI windows_unhandled_exception_filter(EXCEPTION_POINTERS* exceptionPointers) return true;
}
std::vector<std::string> socket_paths_receive(Socket& socket)
{
uint32_t count{};
if (!socket.receive(&count, sizeof(count))) return {};
count = ntohl(count);
std::vector<std::string> paths;
paths.reserve(count);
for (uint32_t i = 0; i < count; ++i)
{ {
windows_minidump_write(exceptionPointers); uint32_t length{};
return EXCEPTION_EXECUTE_HANDLER; if (!socket.receive(&length, sizeof(length))) return {};
length = ntohl(length);
std::string path(length, '\0');
if (length > 0 && !socket.receive(path.data(), length)) return {};
paths.emplace_back(std::move(path));
} }
LONG CALLBACK windows_vectored_exception_handler(EXCEPTION_POINTERS* exceptionPointers) return paths;
{
windows_minidump_write(exceptionPointers);
return EXCEPTION_CONTINUE_SEARCH;
}
void windows_minidumps_configure()
{
auto prefDir = sdl::preferences_directory_get();
if (prefDir.empty()) return;
std::error_code ec{};
auto dumpDir = prefDir / "crash";
std::filesystem::create_directories(dumpDir, ec);
if (ec) return;
g_minidump_dir = dumpDir;
if (!g_vectored_handler) g_vectored_handler = AddVectoredExceptionHandler(1, windows_vectored_exception_handler);
SetUnhandledExceptionFilter(windows_unhandled_exception_filter);
logger.info(std::format("MiniDumpWriteDump enabled: {}", path::to_utf8(dumpDir)));
}
#endif
bool socket_paths_send(Socket& socket, const std::vector<std::string>& paths)
{
uint32_t count = htonl(static_cast<uint32_t>(paths.size()));
if (!socket.send(&count, sizeof(count))) return false;
for (const auto& path : paths)
{
uint32_t length = htonl(static_cast<uint32_t>(path.size()));
if (!socket.send(&length, sizeof(length))) return false;
if (!path.empty() && !socket.send(path.data(), path.size())) return false;
}
return true;
}
std::vector<std::string> socket_paths_receive(Socket& socket)
{
uint32_t count{};
if (!socket.receive(&count, sizeof(count))) return {};
count = ntohl(count);
std::vector<std::string> paths;
paths.reserve(count);
for (uint32_t i = 0; i < count; ++i)
{
uint32_t length{};
if (!socket.receive(&length, sizeof(length))) return {};
length = ntohl(length);
std::string path(length, '\0');
if (length > 0 && !socket.receive(path.data(), length)) return {};
paths.emplace_back(std::move(path));
}
return paths;
}
} }
std::filesystem::path Loader::settings_path() { return sdl::preferences_directory_get() / "settings.ini"; } std::filesystem::path Loader::settings_path() { return sdl::preferences_directory_get() / "settings.ini"; }
@@ -217,10 +135,6 @@ namespace anm2ed
logger.info("Initialized SDL"); logger.info("Initialized SDL");
#ifdef _WIN32
windows_minidumps_configure();
#endif
auto windowProperties = SDL_CreateProperties(); auto windowProperties = SDL_CreateProperties();
if (windowProperties == 0) if (windowProperties == 0)