mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-03 00:02:14 +00:00
fix: out-of-memory on Windows crashes with no dialog and a misleading stack (#14807)
This commit is contained in:
@@ -24,6 +24,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
#include <atomic>
|
||||||
|
#include <new>
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__LINUX__)
|
#if defined(__linux__) || defined(__LINUX__)
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
@@ -7608,6 +7610,9 @@ LONG WINAPI VectoredExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo)
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
// Guards against a failed allocation inside the dump re-entering the new-handler.
|
||||||
|
static std::atomic<bool> g_dump_in_progress{false};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
__declspec(dllexport) int __stdcall orcaslicer_main(int argc, wchar_t **argv)
|
__declspec(dllexport) int __stdcall orcaslicer_main(int argc, wchar_t **argv)
|
||||||
{
|
{
|
||||||
@@ -7626,10 +7631,22 @@ extern "C" {
|
|||||||
//AddVectoredExceptionHandler(1, CBaseException::UnhandledExceptionFilter);
|
//AddVectoredExceptionHandler(1, CBaseException::UnhandledExceptionFilter);
|
||||||
SET_DEFULTER_HANDLER();
|
SET_DEFULTER_HANDLER();
|
||||||
#endif
|
#endif
|
||||||
|
// Dump before unwinding, while the stack still names what asked for the memory. Throwing
|
||||||
|
// std::bad_alloc is standard-permitted here and is what reaches generic_exception_handle().
|
||||||
std::set_new_handler([]() {
|
std::set_new_handler([]() {
|
||||||
int *a = nullptr;
|
if (!g_dump_in_progress.exchange(true)) {
|
||||||
*a = 0;
|
try {
|
||||||
});
|
// A null EXCEPTION_POINTERS walks the calling thread as it stands.
|
||||||
|
CBaseException base(GetCurrentProcess(), GetCurrentProcessId(), NULL, nullptr);
|
||||||
|
base.ShowCallstack();
|
||||||
|
} catch (...) {
|
||||||
|
// A failed dump must not displace the std::bad_alloc owed to the caller.
|
||||||
|
}
|
||||||
|
// ObjParser recovers from std::bad_alloc, so let a later one dump again.
|
||||||
|
g_dump_in_progress = false;
|
||||||
|
}
|
||||||
|
throw std::bad_alloc();
|
||||||
|
});
|
||||||
// Call the UTF8 main.
|
// Call the UTF8 main.
|
||||||
return CLI().run(argc, argv_ptrs.data());
|
return CLI().run(argc, argv_ptrs.data());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user