summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/modules/flow/ff.c31
-rw-r--r--src/modules/flow/ff.h2
2 files changed, 16 insertions, 17 deletions
diff --git a/src/modules/flow/ff.c b/src/modules/flow/ff.c
index 18b55d2..a0ab56c 100644
--- a/src/modules/flow/ff.c
+++ b/src/modules/flow/ff.c
@@ -26,6 +26,19 @@ void ff_populate(ff_t *ff, unsigned idx)
}
+ff_t * ff_free(ff_t *ff)
+{
+ if (ff) {
+ for (int i = 0; i < 2; i++)
+ free(ff->fields[i]);
+
+ free(ff);
+ }
+
+ return NULL;
+}
+
+
ff_t * ff_new(unsigned size, void (*populator)(void *context, unsigned size, const v3f_t *other, v3f_t *field), void *context)
{
ff_t *ff;
@@ -36,13 +49,8 @@ ff_t * ff_new(unsigned size, void (*populator)(void *context, unsigned size, con
for (int i = 0; i < 2; i++) {
ff->fields[i] = calloc(size * size * size, sizeof(v3f_t));
- if (!ff->fields[i]) {
- for (int j = 0; j < i; j++)
- free(ff->fields[j]);
-
- free(ff);
- return NULL;
- }
+ if (!ff->fields[i])
+ return ff_free(ff);
}
ff->size = size;
@@ -56,15 +64,6 @@ ff_t * ff_new(unsigned size, void (*populator)(void *context, unsigned size, con
}
-void ff_free(ff_t *ff)
-{
- for (int i = 0; i < 2; i++)
- free(ff->fields[i]);
-
- free(ff);
-}
-
-
static inline v3f_t ff_sample(v3f_t *field, size_t size, v3f_t *min, v3f_t *max, v3f_t *t)
{
v3f_t *a, *b, *c, *d, *e, *f, *g, *h;
diff --git a/src/modules/flow/ff.h b/src/modules/flow/ff.h
index 4d30143..0324ea0 100644
--- a/src/modules/flow/ff.h
+++ b/src/modules/flow/ff.h
@@ -6,7 +6,7 @@
typedef struct ff_t ff_t;
ff_t * ff_new(unsigned size, void (*populator)(void *context, unsigned size, const v3f_t *other, v3f_t *field), void *context);
-void ff_free(ff_t *ff);
+ff_t * ff_free(ff_t *ff);
v3f_t ff_get(ff_t *ff, v3f_t *coordinate, float w);
void ff_populate(ff_t *ff, unsigned idx);
© All Rights Reserved