mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-23 15:06:32 +00:00
Add out of memory logging on rdcstr/rdcarray
This commit is contained in:
@@ -267,6 +267,10 @@ struct ItemDestroyHelper<T, true>
|
||||
static void destroyRange(T *first, size_t itemCount) {}
|
||||
};
|
||||
|
||||
#ifdef RENDERDOC_EXPORTS
|
||||
void RENDERDOC_OutOfMemory(uint64_t sz);
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user