From e7688526456bba02c88ffdd2e42ae9341e709f79 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 8 Apr 2015 20:02:22 -0700 Subject: [PATCH 1/3] 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; } From 76d6c6cac5b3a097301a16d9f554ff2591e66d93 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 8 Apr 2015 20:03:42 -0700 Subject: [PATCH 2/3] Delete char* items properly --- libraries/octree/src/Octree.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index f4121d051f..b1e92e2140 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -1024,7 +1024,7 @@ int Octree::encodeTreeBitstream(OctreeElement* element, roomForOctalCode = packetData->startSubTree(newCode); if (newCode) { - delete newCode; + delete[] newCode; codeLength = numberOfThreeBitSectionsInCode(newCode); } else { codeLength = 1; @@ -2064,7 +2064,7 @@ bool Octree::readJSONFromStream(unsigned long streamLength, QDataStream& inputSt QVariant asVariant = asDocument.toVariant(); QVariantMap asMap = asVariant.toMap(); readFromMap(asMap); - delete rawData; + delete[] rawData; return true; } From b2dd53ac431f2d76c41b6d35d47910f18439edee Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 9 Apr 2015 08:37:24 -0700 Subject: [PATCH 3/3] Coding standard --- libraries/gpu/src/gpu/Resource.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/gpu/src/gpu/Resource.cpp b/libraries/gpu/src/gpu/Resource.cpp index e9be897170..a13a5cc444 100644 --- a/libraries/gpu/src/gpu/Resource.cpp +++ b/libraries/gpu/src/gpu/Resource.cpp @@ -29,8 +29,7 @@ Resource::Size Resource::Sysmem::allocateMemory(Byte** dataAllocated, Size size) newSize = size; try { (*dataAllocated) = new Byte[newSize]; - } - catch (const std::bad_alloc&) { + } 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; }