_lovrAlloc throws on OOM;

This commit is contained in:
bjorn 2018-12-18 22:40:43 -08:00 committed by Bjorn Swenson
parent ab8e86b9a5
commit 58950aa20e
1 changed files with 6 additions and 4 deletions

View File

@ -29,10 +29,12 @@ void lovrThrow(const char* format, ...) {
}
void* _lovrAlloc(const char* type, size_t size, void (*destructor)(void*)) {
void* object = calloc(1, size);
if (!object) return NULL;
*((Ref*) object) = (Ref) { .free = destructor, .type = type, .count = 1 };
return object;
Ref* ref = calloc(1, size);
if (!ref) return lovrThrow("Out of memory"), NULL;
ref->free = destructor;
ref->type = type;
ref->count = 1;
return ref;
}
void lovrRetain(void* object) {