Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ogt_vox: split fatal errors and warnings #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/demo_vox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool demo_load_and_save(const char *filename)
for (uint32_t instance_index = 0; instance_index < scene->num_instances; instance_index++)
{
const ogt_vox_instance* instance = &scene->instances[instance_index];
const ogt_vox_model* model = scene->models[instance->model_index];
// const ogt_vox_model* model = scene->models[instance->model_index];

const char* layer_name =
instance->layer_index == UINT32_MAX ? "(no layer)":
Expand Down
33 changes: 20 additions & 13 deletions src/ogt_vox.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
eg.
#include "my_assert.h"
#define ogt_assert(condition, message_str) my_assert(condition, message_str)
#define ogt_warn(condition, message_str) my_assert(condition, message_str)

#define OGT_VOX_IMPLEMENTATION
#include "path/to/ogt_vox.h"
Expand Down Expand Up @@ -483,6 +484,9 @@
#ifndef ogt_assert
#include <assert.h>
#define ogt_assert(x, msg_str) do { assert((x) && (msg_str)); } while(0)
#endif
#ifndef ogt_warn
#define ogt_warn(x, msg_str) ogt_assert(x, msg_str)
#endif
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -1008,7 +1012,7 @@
if (!str)
return default_value;
uint32_t value;
_vox_str_scanf(str, "%i", &value);
_vox_str_scanf(str, "%u", &value);
return value;
}

Expand Down Expand Up @@ -1225,7 +1229,7 @@
}
default:
{
ogt_assert(0, "unhandled node type");
ogt_warn(0, "unhandled node type");
}
}
}
Expand Down Expand Up @@ -1470,8 +1474,11 @@
uint8_t y = packed_voxel_data[i * 4 + 1];
uint8_t z = packed_voxel_data[i * 4 + 2];
uint8_t color_index = packed_voxel_data[i * 4 + 3];
ogt_assert(x < size_x && y < size_y && z < size_z, "invalid data in XYZI chunk");
voxel_data[(x * k_stride_x) + (y * k_stride_y) + (z * k_stride_z)] = color_index;
const bool inside_region = x < size_x && y < size_y && z < size_z;
ogt_warn(inside_region, "invalid data in XYZI chunk");
if (inside_region) {
voxel_data[(x * k_stride_x) + (y * k_stride_y) + (z * k_stride_z)] = color_index;
}
}
_vox_file_seek_forwards(fp, num_voxels_in_chunk * 4);
// compute the hash of the voxels in this model-- used to accelerate duplicate models checking.
Expand Down Expand Up @@ -1509,8 +1516,8 @@
_vox_file_read_uint32(fp, &reserved_id);
_vox_file_read_uint32(fp, &layer_id);
_vox_file_read_uint32(fp, &num_frames);
ogt_assert(reserved_id == UINT32_MAX, "unexpected values for reserved_id in nTRN chunk");
ogt_assert(num_frames > 0, "must have at least 1 frame in nTRN chunk");
ogt_warn(reserved_id == UINT32_MAX, "unexpected values for reserved_id in nTRN chunk");
ogt_warn(num_frames > 0, "must have at least 1 frame in nTRN chunk");

// make space in misc_data array for the number of transforms we'll need for this node
ogt_vox_keyframe_transform* keyframes = misc_data.alloc_many<ogt_vox_keyframe_transform>(num_frames);
Expand Down Expand Up @@ -1624,7 +1631,7 @@
_vox_file_read_int32(fp, &layer_id);
_vox_file_read_dict(&dict, fp);
_vox_file_read_int32(fp, &reserved_id);
ogt_assert(reserved_id == -1, "unexpected value for reserved_id in LAYR chunk");
ogt_warn(reserved_id == -1, "unexpected value for reserved_id in LAYR chunk");

layers.grow_to_fit_index(layer_id);
layers[layer_id].name = NULL;
Expand Down Expand Up @@ -1860,8 +1867,8 @@

if (g_progress_callback_func) {
// we indicate progress as 0.8f * amount of buffer read + 0.2f at end after processing
if (!g_progress_callback_func(0.8f*(float)(fp->offset)/(float)(fp->buffer_size), g_progress_callback_user_data))
{
const float progress = 0.8f * (float)(fp->offset) / (float)(fp->buffer_size);
if (!g_progress_callback_func(progress, g_progress_callback_user_data)) {
return 0;
}
}
Expand Down Expand Up @@ -2253,10 +2260,10 @@
is_negative = f[i] < 0.0f ? true : false;
}
else {
ogt_assert(f[i] == 0.0f, "rotation vector should contain only 0.0f, 1.0f, or -1.0f");
ogt_warn(f[i] == 0.0f, "rotation vector should contain only 0.0f, 1.0f, or -1.0f");
}
}
ogt_assert(out_index != 3, "rotation vector was all zeroes but it should be a cardinal axis vector");
ogt_warn(out_index != 3, "rotation vector was all zeroes but it should be a cardinal axis vector");
return is_negative;
}

Expand All @@ -2269,7 +2276,7 @@
bool row0_negative = _vox_get_vec3_rotation_bits(row0, row0_index);
bool row1_negative = _vox_get_vec3_rotation_bits(row1, row1_index);
bool row2_negative = _vox_get_vec3_rotation_bits(row2, row2_index);
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.
ogt_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.
return (row0_index) | (row1_index << 2) | (row0_negative ? 1 << 4 : 0) | (row1_negative ? 1 << 5 : 0) | (row2_negative ? 1 << 6 : 0);
}

Expand Down Expand Up @@ -2738,7 +2745,7 @@
// check that the buffer is not larger than the maximum file size, return nothing if would overflow
if (fp->data.count > UINT32_MAX || (fp->data.count - offset_post_main_chunk) > UINT32_MAX)
{
ogt_assert(0, "Generated file size exceeded 4GiB, which is too large for Magicavoxel to parse.");
ogt_warn(0, "Generated file size exceeded 4GiB, which is too large for Magicavoxel to parse.");
*buffer_size = 0;
return NULL; // note: fp will be freed in dtor on exit
}
Expand Down
2 changes: 1 addition & 1 deletion src/ogt_voxel_meshify.h
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ int32_t _construct_polygon_for_slice(ogt_mesh_vec2i* verts, uint32_t max_verts,

// (1) try tessellate edge0, edge1, edge2.
const uint32_t k_max_tessellations = 512;
assert(edge1_pushed_distance < k_max_tessellations);
assert(edge1_pushed_distance < (int)k_max_tessellations);
ogt_mesh_vec2i tess_buffer[k_max_tessellations];
uint32_t tess_offset = 0;

Expand Down
Loading