From 0528d92d738beb8d33ba047a0c4ef91d93bcdc03 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Tue, 25 Feb 2025 14:47:29 -0800 Subject: [PATCH] Fix compiling on arm64 Linux --- modules/gltf/gltf_document.cpp | 84 +++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index dd27fef7ad0..45778b071ab 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -1198,10 +1198,11 @@ Error GLTFDocument::_encode_buffer_view(Ref p_state, const double *p_ dst_i++; } } - int64_t old_size = gltf_buffer.size(); - gltf_buffer.resize(old_size + (buffer.size() * sizeof(int8_t))); - memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(int8_t)); - bv->byte_length = buffer.size() * sizeof(int8_t); + const int64_t old_size = gltf_buffer.size(); + const size_t buffer_size = buffer.size() * sizeof(int8_t); + gltf_buffer.resize(old_size + buffer_size); + memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size); + bv->byte_length = buffer_size; } break; case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_BYTE: { Vector buffer; @@ -1223,7 +1224,8 @@ Error GLTFDocument::_encode_buffer_view(Ref p_state, const double *p_ } } gltf_buffer.append_array(buffer); - bv->byte_length = buffer.size() * sizeof(uint8_t); + const size_t buffer_size = buffer.size() * sizeof(uint8_t); + bv->byte_length = buffer_size; } break; case GLTFAccessor::COMPONENT_TYPE_SIGNED_SHORT: { Vector buffer; @@ -1244,10 +1246,11 @@ Error GLTFDocument::_encode_buffer_view(Ref p_state, const double *p_ dst_i++; } } - int64_t old_size = gltf_buffer.size(); - gltf_buffer.resize(old_size + (buffer.size() * sizeof(int16_t))); - memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(int16_t)); - bv->byte_length = buffer.size() * sizeof(int16_t); + const int64_t old_size = gltf_buffer.size(); + const size_t buffer_size = buffer.size() * sizeof(int16_t); + gltf_buffer.resize(old_size + buffer_size); + memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size); + bv->byte_length = buffer_size; } break; case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_SHORT: { Vector buffer; @@ -1268,10 +1271,11 @@ Error GLTFDocument::_encode_buffer_view(Ref p_state, const double *p_ dst_i++; } } - int64_t old_size = gltf_buffer.size(); - gltf_buffer.resize(old_size + (buffer.size() * sizeof(uint16_t))); - memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(uint16_t)); - bv->byte_length = buffer.size() * sizeof(uint16_t); + const int64_t old_size = gltf_buffer.size(); + const size_t buffer_size = buffer.size() * sizeof(uint16_t); + gltf_buffer.resize(old_size + buffer_size); + memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size); + bv->byte_length = buffer_size; } break; case GLTFAccessor::COMPONENT_TYPE_SIGNED_INT: { Vector buffer; @@ -1288,10 +1292,11 @@ Error GLTFDocument::_encode_buffer_view(Ref p_state, const double *p_ dst_i++; } } - int64_t old_size = gltf_buffer.size(); - gltf_buffer.resize(old_size + (buffer.size() * sizeof(uint32_t))); - memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(uint32_t)); - bv->byte_length = buffer.size() * sizeof(uint32_t); + const int64_t old_size = gltf_buffer.size(); + const size_t buffer_size = buffer.size() * sizeof(int32_t); + gltf_buffer.resize(old_size + buffer_size); + memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size); + bv->byte_length = buffer_size; } break; case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_INT: { Vector buffer; @@ -1308,10 +1313,11 @@ Error GLTFDocument::_encode_buffer_view(Ref p_state, const double *p_ dst_i++; } } - int64_t old_size = gltf_buffer.size(); - gltf_buffer.resize(old_size + (buffer.size() * sizeof(uint32_t))); - memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(uint32_t)); - bv->byte_length = buffer.size() * sizeof(uint32_t); + const int64_t old_size = gltf_buffer.size(); + const size_t buffer_size = buffer.size() * sizeof(uint32_t); + gltf_buffer.resize(old_size + buffer_size); + memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size); + bv->byte_length = buffer_size; } break; case GLTFAccessor::COMPONENT_TYPE_SINGLE_FLOAT: { Vector buffer; @@ -1328,10 +1334,11 @@ Error GLTFDocument::_encode_buffer_view(Ref p_state, const double *p_ dst_i++; } } - int64_t old_size = gltf_buffer.size(); - gltf_buffer.resize(old_size + (buffer.size() * sizeof(float))); - memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(float)); - bv->byte_length = buffer.size() * sizeof(float); + const int64_t old_size = gltf_buffer.size(); + const size_t buffer_size = buffer.size() * sizeof(float); + gltf_buffer.resize(old_size + buffer_size); + memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size); + bv->byte_length = buffer_size; } break; case GLTFAccessor::COMPONENT_TYPE_DOUBLE_FLOAT: { Vector buffer; @@ -1348,10 +1355,11 @@ Error GLTFDocument::_encode_buffer_view(Ref p_state, const double *p_ dst_i++; } } - int64_t old_size = gltf_buffer.size(); - gltf_buffer.resize(old_size + (buffer.size() * sizeof(double))); - memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(double)); - bv->byte_length = buffer.size() * sizeof(double); + const int64_t old_size = gltf_buffer.size(); + const size_t buffer_size = buffer.size() * sizeof(double); + gltf_buffer.resize(old_size + buffer_size); + memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size); + bv->byte_length = buffer_size; } break; case GLTFAccessor::COMPONENT_TYPE_HALF_FLOAT: { ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "glTF: Half float not supported yet."); @@ -1372,10 +1380,11 @@ Error GLTFDocument::_encode_buffer_view(Ref p_state, const double *p_ dst_i++; } } - int64_t old_size = gltf_buffer.size(); - gltf_buffer.resize(old_size + (buffer.size() * sizeof(int64_t))); - memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(int64_t)); - bv->byte_length = buffer.size() * sizeof(int64_t); + const int64_t old_size = gltf_buffer.size(); + const size_t buffer_size = buffer.size() * sizeof(int64_t); + gltf_buffer.resize(old_size + buffer_size); + memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size); + bv->byte_length = buffer_size; } break; case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_LONG: { Vector buffer; @@ -1393,10 +1402,11 @@ Error GLTFDocument::_encode_buffer_view(Ref p_state, const double *p_ dst_i++; } } - int64_t old_size = gltf_buffer.size(); - gltf_buffer.resize(old_size + (buffer.size() * sizeof(uint64_t))); - memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(uint64_t)); - bv->byte_length = buffer.size() * sizeof(uint64_t); + const int64_t old_size = gltf_buffer.size(); + const size_t buffer_size = buffer.size() * sizeof(uint64_t); + gltf_buffer.resize(old_size + buffer_size); + memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size); + bv->byte_length = buffer_size; } break; } ERR_FAIL_COND_V(buffer_end > bv->byte_length, ERR_INVALID_DATA);