From http://www.jwz.org/xscreensaver/xscreensaver-5.40.tar.gz
[xscreensaver] / hacks / glx / quickhull.c
index bf3036a1539bd61ded1953317c36c3227adafa0b..4c46ca0887f4c4fc3e73fb9482c16d9a2093e5e6 100644 (file)
 # include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+extern const char *progname;
+
 #include "quickhull.h"
 
+#include "screenhackI.h" /* for jwxyz_abort */
+
 #include <math.h>   /* sqrt & fabs */
 #include <stdio.h>  /* FILE */
 #include <string.h> /* memcpy */
@@ -1189,6 +1193,22 @@ qh__init_context(qh_context_t* context, qh_vertex_t const* vertices,
   context->newhorizonedges.begin = QH_MALLOC(qh_index_t, nedges);
   context->valid = QH_MALLOC(char, nfaces);
 
+  if (!(context->edges &&
+        context->faces &&
+        context->facestack.begin &&
+        context->scratch.begin &&
+        context->horizonedges.begin &&
+        context->newhorizonedges.begin &&
+        context->valid)) {
+# ifdef HAVE_JWXYZ
+    jwxyz_abort ("%s: out of memory", progname);
+# else
+    fprintf (stderr, "%s: out of memory\n", progname);
+    exit (1);
+# endif
+  }
+
+
   context->vertices = QH_MALLOC(qh_vertex_t, nvertices);
   memcpy(context->vertices, vertices, sizeof(qh_vertex_t) * nvertices);