Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2025-05-07 04:49:52 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2025-05-07 04:49:52 +1000
commit3a54621bd8a55b672ba986f02ab094bfb4ba6faf (patch)
tree4cba881b3c8518b7be01fc8225a0877406aee16e /source/core
parent37fab128ceccfafac99d33e84c768e85aead6d60 (diff)
add world.template, world.setTemplate
Diffstat (limited to 'source/core')
-rw-r--r--source/core/CMakeLists.txt2
-rw-r--r--source/core/StarMiniDump.hpp11
-rw-r--r--source/core/StarMiniDump_windows.cpp28
-rw-r--r--source/core/StarSignalHandler_windows.cpp39
4 files changed, 49 insertions, 31 deletions
diff --git a/source/core/CMakeLists.txt b/source/core/CMakeLists.txt
index 63f86cf..b510b50 100644
--- a/source/core/CMakeLists.txt
+++ b/source/core/CMakeLists.txt
@@ -69,6 +69,7 @@ SET (star_core_HEADERS
StarMatrix3.hpp
StarMaybe.hpp
StarMemory.hpp
+ StarMiniDump.hpp
StarMultiArray.hpp
StarMultiArrayInterpolator.hpp
StarMultiTable.hpp
@@ -216,6 +217,7 @@ ELSEIF (STAR_SYSTEM_FAMILY_WINDOWS)
StarDynamicLib_windows.cpp
StarFile_windows.cpp
StarLockFile_windows.cpp
+ StarMiniDump_windows.cpp
StarSignalHandler_windows.cpp
StarString_windows.cpp
StarThread_windows.cpp
diff --git a/source/core/StarMiniDump.hpp b/source/core/StarMiniDump.hpp
new file mode 100644
index 0000000..f911f14
--- /dev/null
+++ b/source/core/StarMiniDump.hpp
@@ -0,0 +1,11 @@
+#pragma once
+
+#ifdef STAR_SYSTEM_WINDOWS
+#include <windows.h>
+#endif
+
+namespace Star {
+#ifdef STAR_SYSTEM_WINDOWS
+ DWORD WINAPI writeMiniDump(void* ExceptionInfo);
+#endif
+} \ No newline at end of file
diff --git a/source/core/StarMiniDump_windows.cpp b/source/core/StarMiniDump_windows.cpp
new file mode 100644
index 0000000..368d67d
--- /dev/null
+++ b/source/core/StarMiniDump_windows.cpp
@@ -0,0 +1,28 @@
+#include "StarMiniDump.hpp"
+#include <windows.h>
+#include "minidumpapiset.h"
+
+namespace Star {
+ DWORD WINAPI writeMiniDump(void* ExceptionInfo) {
+ auto hFile = CreateFileA("starbound.dmp", GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
+ if (hFile == INVALID_HANDLE_VALUE)
+ return 0;
+ MINIDUMP_EXCEPTION_INFORMATION dumpExceptionInfo{};
+ dumpExceptionInfo.ThreadId = GetCurrentThreadId();
+ dumpExceptionInfo.ExceptionPointers = (PEXCEPTION_POINTERS)ExceptionInfo;
+ dumpExceptionInfo.ClientPointers = FALSE;
+ MiniDumpWriteDump(
+ GetCurrentProcess(),
+ GetCurrentProcessId(),
+ hFile,
+ MiniDumpNormal,
+ &dumpExceptionInfo,
+ NULL,
+ NULL);
+ CloseHandle(hFile);
+ if (dumpExceptionInfo.ExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) {
+ MessageBoxA(NULL, "Stack overflow encountered\nA minidump has been generated", NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
+ }
+ return 0;
+ };
+} \ No newline at end of file
diff --git a/source/core/StarSignalHandler_windows.cpp b/source/core/StarSignalHandler_windows.cpp
index 2fbde88..a3b4478 100644
--- a/source/core/StarSignalHandler_windows.cpp
+++ b/source/core/StarSignalHandler_windows.cpp
@@ -1,38 +1,15 @@
+#include "StarMiniDump.hpp"
#include "StarSignalHandler.hpp"
#include "StarFormat.hpp"
#include "StarString.hpp"
#include "StarLogging.hpp"
#include <windows.h>
-#include "minidumpapiset.h"
namespace Star {
String g_sehMessage;
-static DWORD WINAPI writeMiniDump(void* ExceptionInfo) {
- auto hFile = CreateFileA("starbound.dmp", GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
- if (hFile == INVALID_HANDLE_VALUE)
- return 0;
- MINIDUMP_EXCEPTION_INFORMATION dumpExceptionInfo{};
- dumpExceptionInfo.ThreadId = GetCurrentThreadId();
- dumpExceptionInfo.ExceptionPointers = (PEXCEPTION_POINTERS)ExceptionInfo;
- dumpExceptionInfo.ClientPointers = FALSE;
- MiniDumpWriteDump(
- GetCurrentProcess(),
- GetCurrentProcessId(),
- hFile,
- MiniDumpNormal,
- &dumpExceptionInfo,
- NULL,
- NULL);
- CloseHandle(hFile);
- if (dumpExceptionInfo.ExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) {
- MessageBoxA(NULL, "Fatal stack overflow encountered\nA minidump has been generated", NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
- }
- return 0;
-};
-
struct SignalHandlerImpl {
bool handlingFatal;
bool handlingInterrupt;
@@ -122,10 +99,14 @@ struct SignalHandlerImpl {
}
static LONG CALLBACK vectoredExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) {
- HANDLE thread = NULL;
LONG result = EXCEPTION_CONTINUE_SEARCH;
if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) {
- thread = CreateThread(NULL, 0, writeMiniDump, (void*)ExceptionInfo, 0, NULL);
+ if (HANDLE thread = CreateThread(NULL, 0, writeMiniDump, (void*)ExceptionInfo, 0, NULL)) {
+ WaitForSingleObject(thread, 10000);
+ CloseHandle(thread);
+ }
+ handleFatalError("Stack overflow detected", ExceptionInfo);
+ result = EXCEPTION_CONTINUE_EXECUTION;
}
if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) {
handleFatalError("Access violation detected", ExceptionInfo);
@@ -144,7 +125,6 @@ struct SignalHandlerImpl {
|| (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_FLT_OVERFLOW)
|| (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_FLT_STACK_CHECK)
|| (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_FLT_UNDERFLOW)
-
) {
handleFatalError("Floating point exception", ExceptionInfo);
result = EXCEPTION_CONTINUE_EXECUTION;
@@ -169,10 +149,7 @@ struct SignalHandlerImpl {
handleFatalError("Error occurred", ExceptionInfo);
result = EXCEPTION_CONTINUE_EXECUTION;
}
- if (thread != NULL) {
- WaitForSingleObject(thread, 10000);
- CloseHandle(thread);
- }
+
return result;
}