From 2b087cb45ae91f90492a935625570d7d42ee3ecb Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 7 Apr 2010 14:26:15 -0400 Subject: New dmnsn_malloc() function, and friends. I'm tired of checking for malloc failures everywhere, considering it never happens. So just bail out whenever it does. A lot of stuff is guaranteed to succeed if it returns now. --- libdimension/scene.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'libdimension/scene.c') diff --git a/libdimension/scene.c b/libdimension/scene.c index 4595afd..dbda90b 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -20,37 +20,28 @@ #include "dimension.h" #include -#include /* For malloc */ #include /* For sysconf */ /* Allocate an empty scene */ dmnsn_scene * dmnsn_new_scene() { - dmnsn_scene *scene = malloc(sizeof(dmnsn_scene)); - if (scene) { - scene->default_texture = dmnsn_new_texture(); - if (!scene->default_texture) { - dmnsn_delete_scene(scene); - errno = ENOMEM; - return NULL; - } + dmnsn_scene *scene = dmnsn_malloc(sizeof(dmnsn_scene)); - scene->camera = NULL; - scene->canvas = NULL; - scene->objects = dmnsn_new_array(sizeof(dmnsn_object *)); - scene->lights = dmnsn_new_array(sizeof(dmnsn_light *)); - scene->quality = DMNSN_RENDER_FULL; - scene->reclimit = 5; + scene->default_texture = dmnsn_new_texture(); + scene->camera = NULL; + scene->canvas = NULL; + scene->objects = dmnsn_new_array(sizeof(dmnsn_object *)); + scene->lights = dmnsn_new_array(sizeof(dmnsn_light *)); + scene->quality = DMNSN_RENDER_FULL; + scene->reclimit = 5; + + /* Find the number of processors/cores running (TODO: do this portably) */ + int nprocs = sysconf(_SC_NPROCESSORS_ONLN); + if (nprocs < 1) + nprocs = 1; + scene->nthreads = nprocs; - /* Find the number of processors/cores running (TODO: do this portably) */ - int nprocs = sysconf(_SC_NPROCESSORS_ONLN); - if (nprocs < 1) - nprocs = 1; - scene->nthreads = nprocs; - } else { - errno = ENOMEM; - } return scene; } -- cgit v1.2.3