summaryrefslogtreecommitdiffstats
path: root/libdimension/scene.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-04-07 14:26:15 -0400
committerTavian Barnes <tavianator@gmail.com>2010-04-07 14:34:52 -0400
commit2b087cb45ae91f90492a935625570d7d42ee3ecb (patch)
treea464213b08d04c8c91c8879a84e534f895c84378 /libdimension/scene.c
parent7d6663eeb68bf9d0a3dff86128827c0c1d85df69 (diff)
downloaddimension-2b087cb45ae91f90492a935625570d7d42ee3ecb.tar.xz
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.
Diffstat (limited to 'libdimension/scene.c')
-rw-r--r--libdimension/scene.c37
1 files changed, 14 insertions, 23 deletions
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 <errno.h>
-#include <stdlib.h> /* For malloc */
#include <unistd.h> /* 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;
}