Merge pull request #449 from emimvi/consistent_byteOffset

Always use size_t for byte offsets
This commit is contained in:
Syoyo Fujita 2023-09-03 02:20:35 +09:00 committed by GitHub
commit 3d445cc65d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -837,7 +837,7 @@ struct Accessor {
int count; int count;
bool isSparse; bool isSparse;
struct { struct {
int byteOffset; size_t byteOffset;
int bufferView; int bufferView;
int componentType; // a TINYGLTF_COMPONENT_TYPE_ value int componentType; // a TINYGLTF_COMPONENT_TYPE_ value
Value extras; Value extras;
@ -847,7 +847,7 @@ struct Accessor {
} indices; } indices;
struct { struct {
int bufferView; int bufferView;
int byteOffset; size_t byteOffset;
Value extras; Value extras;
ExtensionMap extensions; ExtensionMap extensions;
std::string extras_json_string; std::string extras_json_string;
@ -4648,24 +4648,26 @@ static bool ParseSparseAccessor(
const detail::json &indices_obj = detail::GetValue(indices_iterator); const detail::json &indices_obj = detail::GetValue(indices_iterator);
const detail::json &values_obj = detail::GetValue(values_iterator); const detail::json &values_obj = detail::GetValue(values_iterator);
int indices_buffer_view = 0, indices_byte_offset = 0, component_type = 0; int indices_buffer_view = 0, component_type = 0;
size_t indices_byte_offset = 0;
if (!ParseIntegerProperty(&indices_buffer_view, err, indices_obj, if (!ParseIntegerProperty(&indices_buffer_view, err, indices_obj,
"bufferView", true, "SparseAccessor")) { "bufferView", true, "SparseAccessor")) {
return false; return false;
} }
ParseIntegerProperty(&indices_byte_offset, err, indices_obj, "byteOffset", ParseUnsignedProperty(&indices_byte_offset, err, indices_obj, "byteOffset",
false); false);
if (!ParseIntegerProperty(&component_type, err, indices_obj, "componentType", if (!ParseIntegerProperty(&component_type, err, indices_obj, "componentType",
true, "SparseAccessor")) { true, "SparseAccessor")) {
return false; return false;
} }
int values_buffer_view = 0, values_byte_offset = 0; int values_buffer_view = 0;
size_t values_byte_offset = 0;
if (!ParseIntegerProperty(&values_buffer_view, err, values_obj, "bufferView", if (!ParseIntegerProperty(&values_buffer_view, err, values_obj, "bufferView",
true, "SparseAccessor")) { true, "SparseAccessor")) {
return false; return false;
} }
ParseIntegerProperty(&values_byte_offset, err, values_obj, "byteOffset", ParseUnsignedProperty(&values_byte_offset, err, values_obj, "byteOffset",
false); false);
sparse->count = count; sparse->count = count;
@ -7159,7 +7161,7 @@ static void SerializeGltfAccessor(const Accessor &accessor, detail::json &o) {
SerializeNumberProperty<int>("bufferView", accessor.bufferView, o); SerializeNumberProperty<int>("bufferView", accessor.bufferView, o);
if (accessor.byteOffset != 0) if (accessor.byteOffset != 0)
SerializeNumberProperty<int>("byteOffset", int(accessor.byteOffset), o); SerializeNumberProperty<size_t>("byteOffset", accessor.byteOffset, o);
SerializeNumberProperty<int>("componentType", accessor.componentType, o); SerializeNumberProperty<int>("componentType", accessor.componentType, o);
SerializeNumberProperty<size_t>("count", accessor.count, o); SerializeNumberProperty<size_t>("count", accessor.count, o);
@ -7230,7 +7232,7 @@ static void SerializeGltfAccessor(const Accessor &accessor, detail::json &o) {
detail::json indices; detail::json indices;
SerializeNumberProperty<int>("bufferView", SerializeNumberProperty<int>("bufferView",
accessor.sparse.indices.bufferView, indices); accessor.sparse.indices.bufferView, indices);
SerializeNumberProperty<int>("byteOffset", SerializeNumberProperty<size_t>("byteOffset",
accessor.sparse.indices.byteOffset, indices); accessor.sparse.indices.byteOffset, indices);
SerializeNumberProperty<int>( SerializeNumberProperty<int>(
"componentType", accessor.sparse.indices.componentType, indices); "componentType", accessor.sparse.indices.componentType, indices);
@ -7241,7 +7243,7 @@ static void SerializeGltfAccessor(const Accessor &accessor, detail::json &o) {
detail::json values; detail::json values;
SerializeNumberProperty<int>("bufferView", SerializeNumberProperty<int>("bufferView",
accessor.sparse.values.bufferView, values); accessor.sparse.values.bufferView, values);
SerializeNumberProperty<int>("byteOffset", SerializeNumberProperty<size_t>("byteOffset",
accessor.sparse.values.byteOffset, values); accessor.sparse.values.byteOffset, values);
SerializeExtrasAndExtensions(accessor.sparse.values, values); SerializeExtrasAndExtensions(accessor.sparse.values, values);
detail::JsonAddMember(sparse, "values", std::move(values)); detail::JsonAddMember(sparse, "values", std::move(values));