Skip to content

Commit f935d52

Browse files
committed
ogt_vox: added ogt_warn for non fatal errors
1 parent 6e196fe commit f935d52

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/ogt_vox.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
eg.
177177
#include "my_assert.h"
178178
#define ogt_assert(condition, message_str) my_assert(condition, message_str)
179+
#define ogt_assert_warn(condition, message_str) my_assert(condition, message_str)
179180
180181
#define OGT_VOX_IMPLEMENTATION
181182
#include "path/to/ogt_vox.h"
@@ -515,6 +516,9 @@
515516
#ifndef ogt_assert
516517
#include <assert.h>
517518
#define ogt_assert(x, msg_str) do { assert((x) && (msg_str)); } while(0)
519+
#endif
520+
#ifndef ogt_assert_warn
521+
#define ogt_assert_warn(x, msg_str) ogt_assert(x, msg_str)
518522
#endif
519523
#include <stdlib.h>
520524
#include <string.h>
@@ -1282,7 +1286,7 @@
12821286
}
12831287
default:
12841288
{
1285-
ogt_assert(0, "unhandled node type");
1289+
ogt_assert_warn(0, "unhandled node type");
12861290
}
12871291
}
12881292
}
@@ -1577,8 +1581,9 @@
15771581
uint8_t y = packed_voxel_data[i * 4 + 1];
15781582
uint8_t z = packed_voxel_data[i * 4 + 2];
15791583
uint8_t color_index = packed_voxel_data[i * 4 + 3];
1580-
ogt_assert(x < size_x && y < size_y && z < size_z, "invalid data in XYZI chunk");
1581-
if(x < size_x && y < size_y && z < size_z ) {
1584+
const bool inside_region = x < size_x && y < size_y && z < size_z;
1585+
ogt_assert_warn(inside_region, "invalid data in XYZI chunk");
1586+
if (inside_region) {
15821587
voxel_data[(x * k_stride_x) + (y * k_stride_y) + (z * k_stride_z)] = color_index;
15831588
}
15841589
}
@@ -1618,8 +1623,8 @@
16181623
_vox_file_read_uint32(fp, &reserved_id);
16191624
_vox_file_read_uint32(fp, &layer_id);
16201625
_vox_file_read_uint32(fp, &num_frames);
1621-
ogt_assert(reserved_id == UINT32_MAX, "unexpected values for reserved_id in nTRN chunk");
1622-
ogt_assert(num_frames > 0, "must have at least 1 frame in nTRN chunk");
1626+
ogt_assert_warn(reserved_id == UINT32_MAX, "unexpected values for reserved_id in nTRN chunk");
1627+
ogt_assert_warn(num_frames > 0, "must have at least 1 frame in nTRN chunk");
16231628

16241629
// make space in misc_data array for the number of transforms we'll need for this node
16251630
ogt_vox_keyframe_transform* keyframes = misc_data.alloc_many<ogt_vox_keyframe_transform>(num_frames);
@@ -1733,7 +1738,7 @@
17331738
_vox_file_read_int32(fp, &layer_id);
17341739
_vox_file_read_dict(&dict, fp);
17351740
_vox_file_read_int32(fp, &reserved_id);
1736-
ogt_assert(reserved_id == -1, "unexpected value for reserved_id in LAYR chunk");
1741+
ogt_assert_warn(reserved_id == -1, "unexpected value for reserved_id in LAYR chunk");
17371742

17381743
layers.grow_to_fit_index(layer_id);
17391744
layers[layer_id].name = NULL;
@@ -2056,8 +2061,8 @@
20562061

20572062
if (g_progress_callback_func) {
20582063
// we indicate progress as 0.8f * amount of buffer read + 0.2f at end after processing
2059-
if (!g_progress_callback_func(0.8f*(float)(fp->offset)/(float)(fp->buffer_size), g_progress_callback_user_data))
2060-
{
2064+
const float progress = 0.8f * (float)(fp->offset) / (float)(fp->buffer_size);
2065+
if (!g_progress_callback_func(progress, g_progress_callback_user_data)) {
20612066
return 0;
20622067
}
20632068
}
@@ -2483,10 +2488,10 @@
24832488
is_negative = f[i] < 0.0f ? true : false;
24842489
}
24852490
else {
2486-
ogt_assert(f[i] == 0.0f, "rotation vector should contain only 0.0f, 1.0f, or -1.0f");
2491+
ogt_assert_warn(f[i] == 0.0f, "rotation vector should contain only 0.0f, 1.0f, or -1.0f");
24872492
}
24882493
}
2489-
ogt_assert(out_index != 3, "rotation vector was all zeroes but it should be a cardinal axis vector");
2494+
ogt_assert_warn(out_index != 3, "rotation vector was all zeroes but it should be a cardinal axis vector");
24902495
return is_negative;
24912496
}
24922497

@@ -2499,7 +2504,7 @@
24992504
bool row0_negative = _vox_get_vec3_rotation_bits(row0, row0_index);
25002505
bool row1_negative = _vox_get_vec3_rotation_bits(row1, row1_index);
25012506
bool row2_negative = _vox_get_vec3_rotation_bits(row2, row2_index);
2502-
ogt_assert(((1 << row0_index) | (1 << row1_index) | (1 << row2_index)) == 7, "non orthogonal rows found in transform"); // check that rows are orthogonal. There must be a non-zero entry in column 0, 1 and 2 across these 3 rows.
2507+
ogt_assert_warn(((1 << row0_index) | (1 << row1_index) | (1 << row2_index)) == 7, "non orthogonal rows found in transform"); // check that rows are orthogonal. There must be a non-zero entry in column 0, 1 and 2 across these 3 rows.
25032508
return (row0_index) | (row1_index << 2) | (row0_negative ? 1 << 4 : 0) | (row1_negative ? 1 << 5 : 0) | (row2_negative ? 1 << 6 : 0);
25042509
}
25052510

@@ -3054,7 +3059,7 @@
30543059
// check that the buffer is not larger than the maximum file size, return nothing if would overflow
30553060
if (fp->data.count > UINT32_MAX || (fp->data.count - offset_post_main_chunk) > UINT32_MAX)
30563061
{
3057-
ogt_assert(0, "Generated file size exceeded 4GiB, which is too large for Magicavoxel to parse.");
3062+
ogt_assert_warn(0, "Generated file size exceeded 4GiB, which is too large for Magicavoxel to parse.");
30583063
*buffer_size = 0;
30593064
return NULL; // note: fp will be freed in dtor on exit
30603065
}

0 commit comments

Comments
 (0)