diff --git a/renderdoc/api/replay/basic_types.h b/renderdoc/api/replay/basic_types.h index d9e387fb1..a2f844aeb 100644 --- a/renderdoc/api/replay/basic_types.h +++ b/renderdoc/api/replay/basic_types.h @@ -267,6 +267,10 @@ struct ItemDestroyHelper static void destroyRange(T *first, size_t itemCount) {} }; +#ifdef RENDERDOC_EXPORTS +void RENDERDOC_OutOfMemory(uint64_t sz); +#endif + template struct rdcarray { @@ -279,11 +283,15 @@ protected: // memory management, in a dll safe way static T *allocate(size_t count) { + T *ret = NULL; #ifdef RENDERDOC_EXPORTS - return (T *)malloc(count * sizeof(T)); + ret = (T *)malloc(count * sizeof(T)); + if(ret == NULL) + RENDERDOC_OutOfMemory(count * sizeof(T)); #else - return (T *)RENDERDOC_AllocArrayMem(count * sizeof(T)); + ret = (T *)RENDERDOC_AllocArrayMem(count * sizeof(T)); #endif + return ret; } static void deallocate(const T *p) { diff --git a/renderdoc/api/replay/rdcstr.h b/renderdoc/api/replay/rdcstr.h index eb9607748..7d52c6dad 100644 --- a/renderdoc/api/replay/rdcstr.h +++ b/renderdoc/api/replay/rdcstr.h @@ -50,6 +50,10 @@ inline rdcliteral operator"" _lit(const char *str, size_t len) return rdcliteral(str, len); } +#ifdef RENDERDOC_EXPORTS +void RENDERDOC_OutOfMemory(uint64_t sz); +#endif + DOCUMENT(""); class rdcstr { @@ -128,11 +132,15 @@ private: DOCUMENT(""); static char *allocate(size_t count) { + char *ret = NULL; #ifdef RENDERDOC_EXPORTS - return (char *)malloc(count); + ret = (char *)malloc(count); + if(ret == NULL) + RENDERDOC_OutOfMemory(count); #else - return (char *)RENDERDOC_AllocArrayMem(count); + ret = (char *)RENDERDOC_AllocArrayMem(count); #endif + return ret; } static void deallocate(const char *p) { diff --git a/renderdoc/replay/entry_points.cpp b/renderdoc/replay/entry_points.cpp index 3115b36ee..59345337f 100644 --- a/renderdoc/replay/entry_points.cpp +++ b/renderdoc/replay/entry_points.cpp @@ -376,9 +376,18 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_FreeArrayMem(const void *me free((void *)mem); } +// not exported, this is needed for calling from the container allocate functions +void RENDERDOC_OutOfMemory(uint64_t sz) +{ + RDCFATAL("Allocation failed for %llu bytes", sz); +} + extern "C" RENDERDOC_API void *RENDERDOC_CC RENDERDOC_AllocArrayMem(uint64_t sz) { - return malloc((size_t)sz); + void *ret = malloc((size_t)sz); + if(ret == NULL) + RENDERDOC_OutOfMemory(sz); + return ret; } extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_EnumerateRemoteTargets(const char *URL,