From e7688526456bba02c88ffdd2e42ae9341e709f79 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 8 Apr 2015 20:02:22 -0700 Subject: [PATCH] Fix catching bad_alloc Non-allocation wasn't caught on Windows; it just crashed. --- libraries/gpu/src/gpu/Resource.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/gpu/src/gpu/Resource.cpp b/libraries/gpu/src/gpu/Resource.cpp index f1956727f8..e9be897170 100644 --- a/libraries/gpu/src/gpu/Resource.cpp +++ b/libraries/gpu/src/gpu/Resource.cpp @@ -27,9 +27,10 @@ Resource::Size Resource::Sysmem::allocateMemory(Byte** dataAllocated, Size size) if (size > 0) { // Try allocating as much as the required size + one block of memory newSize = size; - (*dataAllocated) = new Byte[newSize]; - // Failed? - if (!(*dataAllocated)) { + try { + (*dataAllocated) = new Byte[newSize]; + } + catch (const std::bad_alloc&) { qWarning() << "Buffer::Sysmem::allocate() : Can't allocate a system memory buffer of " << newSize << "bytes. Fails to create the buffer Sysmem."; return NOT_ALLOCATED; }