提交 56d6d4f0 编写于 作者: M Matt Pharr

Windows: use SetUnhandledExceptionFilter to catch exceptions

This way things like seg faults will no longer cause pbrt to just
silently terminate, which has been fairly confusing behavior...
上级 44bb6a97
......@@ -25,8 +25,35 @@
#include <stdlib.h>
#ifdef PBRT_IS_WINDOWS
#include <Windows.h>
#endif // PBRT_IS_WINDOWS
namespace pbrt {
#ifdef PBRT_IS_WINDOWS
static LONG WINAPI handleExceptions(PEXCEPTION_POINTERS info) {
switch (info->ExceptionRecord->ExceptionCode) {
case EXCEPTION_ACCESS_VIOLATION:
LOG_ERROR("Access violation--terminating execution");
break;
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
LOG_ERROR("Array bounds violation--terminating execution");
break;
case EXCEPTION_DATATYPE_MISALIGNMENT:
LOG_ERROR("Accessed misaligned data--terminating execution");
break;
case EXCEPTION_STACK_OVERFLOW:
LOG_ERROR("Stack overflow--terminating execution");
break;
default:
LOG_ERROR("Program generated exception %d--terminating execution",
int(info->ExceptionRecord->ExceptionCode));
}
return EXCEPTION_EXECUTE_HANDLER;
}
#endif // PBRT_IS_WINDOWS
// API Function Definitions
void InitPBRT(const PBRTOptions &opt) {
Options = new PBRTOptions(opt);
......@@ -34,7 +61,9 @@ void InitPBRT(const PBRTOptions &opt) {
Imf::setGlobalThreadCount(opt.nThreads ? opt.nThreads : AvailableCores());
#if defined(PBRT_IS_WINDOWS) && defined(PBRT_BUILD_GPU_RENDERER)
#if defined(PBRT_IS_WINDOWS)
SetUnhandledExceptionFilter(handleExceptions);
#if defined(PBRT_BUILD_GPU_RENDERER)
if (Options->useGPU && Options->gpuDevice && !getenv("CUDA_VISIBLE_DEVICES")) {
// Limit CUDA to considering only a single GPU on Windows. pbrt
// only uses a single GPU anyway, and if there are multiple GPUs
......@@ -47,7 +76,8 @@ void InitPBRT(const PBRTOptions &opt) {
// is the one to use.
*Options->gpuDevice = 0;
}
#endif // PBRT_IS_WINDOWS && PBRT_BUILD_GPU_RENDERER
#endif // PBRT_BUILD_GPU_RENDERER
#endif // PBRT_IS_WINDOWS
if (Options->quiet)
SuppressErrorMessages();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册