Skip to content

Commit a398f4f

Browse files
authored
Merge pull request #103303 from aaronfranke/fix-compile-arm64-linux
Fix compiling on arm64 Linux with GCC
2 parents bb634fd + 0528d92 commit a398f4f

File tree

1 file changed

+47
-37
lines changed

1 file changed

+47
-37
lines changed

modules/gltf/gltf_document.cpp

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,10 +1198,11 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
11981198
dst_i++;
11991199
}
12001200
}
1201-
int64_t old_size = gltf_buffer.size();
1202-
gltf_buffer.resize(old_size + (buffer.size() * sizeof(int8_t)));
1203-
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(int8_t));
1204-
bv->byte_length = buffer.size() * sizeof(int8_t);
1201+
const int64_t old_size = gltf_buffer.size();
1202+
const size_t buffer_size = buffer.size() * sizeof(int8_t);
1203+
gltf_buffer.resize(old_size + buffer_size);
1204+
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
1205+
bv->byte_length = buffer_size;
12051206
} break;
12061207
case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_BYTE: {
12071208
Vector<uint8_t> buffer;
@@ -1223,7 +1224,8 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
12231224
}
12241225
}
12251226
gltf_buffer.append_array(buffer);
1226-
bv->byte_length = buffer.size() * sizeof(uint8_t);
1227+
const size_t buffer_size = buffer.size() * sizeof(uint8_t);
1228+
bv->byte_length = buffer_size;
12271229
} break;
12281230
case GLTFAccessor::COMPONENT_TYPE_SIGNED_SHORT: {
12291231
Vector<int16_t> buffer;
@@ -1244,10 +1246,11 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
12441246
dst_i++;
12451247
}
12461248
}
1247-
int64_t old_size = gltf_buffer.size();
1248-
gltf_buffer.resize(old_size + (buffer.size() * sizeof(int16_t)));
1249-
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(int16_t));
1250-
bv->byte_length = buffer.size() * sizeof(int16_t);
1249+
const int64_t old_size = gltf_buffer.size();
1250+
const size_t buffer_size = buffer.size() * sizeof(int16_t);
1251+
gltf_buffer.resize(old_size + buffer_size);
1252+
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
1253+
bv->byte_length = buffer_size;
12511254
} break;
12521255
case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_SHORT: {
12531256
Vector<uint16_t> buffer;
@@ -1268,10 +1271,11 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
12681271
dst_i++;
12691272
}
12701273
}
1271-
int64_t old_size = gltf_buffer.size();
1272-
gltf_buffer.resize(old_size + (buffer.size() * sizeof(uint16_t)));
1273-
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(uint16_t));
1274-
bv->byte_length = buffer.size() * sizeof(uint16_t);
1274+
const int64_t old_size = gltf_buffer.size();
1275+
const size_t buffer_size = buffer.size() * sizeof(uint16_t);
1276+
gltf_buffer.resize(old_size + buffer_size);
1277+
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
1278+
bv->byte_length = buffer_size;
12751279
} break;
12761280
case GLTFAccessor::COMPONENT_TYPE_SIGNED_INT: {
12771281
Vector<int32_t> buffer;
@@ -1288,10 +1292,11 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
12881292
dst_i++;
12891293
}
12901294
}
1291-
int64_t old_size = gltf_buffer.size();
1292-
gltf_buffer.resize(old_size + (buffer.size() * sizeof(uint32_t)));
1293-
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(uint32_t));
1294-
bv->byte_length = buffer.size() * sizeof(uint32_t);
1295+
const int64_t old_size = gltf_buffer.size();
1296+
const size_t buffer_size = buffer.size() * sizeof(int32_t);
1297+
gltf_buffer.resize(old_size + buffer_size);
1298+
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
1299+
bv->byte_length = buffer_size;
12951300
} break;
12961301
case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_INT: {
12971302
Vector<uint32_t> buffer;
@@ -1308,10 +1313,11 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
13081313
dst_i++;
13091314
}
13101315
}
1311-
int64_t old_size = gltf_buffer.size();
1312-
gltf_buffer.resize(old_size + (buffer.size() * sizeof(uint32_t)));
1313-
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(uint32_t));
1314-
bv->byte_length = buffer.size() * sizeof(uint32_t);
1316+
const int64_t old_size = gltf_buffer.size();
1317+
const size_t buffer_size = buffer.size() * sizeof(uint32_t);
1318+
gltf_buffer.resize(old_size + buffer_size);
1319+
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
1320+
bv->byte_length = buffer_size;
13151321
} break;
13161322
case GLTFAccessor::COMPONENT_TYPE_SINGLE_FLOAT: {
13171323
Vector<float> buffer;
@@ -1328,10 +1334,11 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
13281334
dst_i++;
13291335
}
13301336
}
1331-
int64_t old_size = gltf_buffer.size();
1332-
gltf_buffer.resize(old_size + (buffer.size() * sizeof(float)));
1333-
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(float));
1334-
bv->byte_length = buffer.size() * sizeof(float);
1337+
const int64_t old_size = gltf_buffer.size();
1338+
const size_t buffer_size = buffer.size() * sizeof(float);
1339+
gltf_buffer.resize(old_size + buffer_size);
1340+
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
1341+
bv->byte_length = buffer_size;
13351342
} break;
13361343
case GLTFAccessor::COMPONENT_TYPE_DOUBLE_FLOAT: {
13371344
Vector<double> buffer;
@@ -1348,10 +1355,11 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
13481355
dst_i++;
13491356
}
13501357
}
1351-
int64_t old_size = gltf_buffer.size();
1352-
gltf_buffer.resize(old_size + (buffer.size() * sizeof(double)));
1353-
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(double));
1354-
bv->byte_length = buffer.size() * sizeof(double);
1358+
const int64_t old_size = gltf_buffer.size();
1359+
const size_t buffer_size = buffer.size() * sizeof(double);
1360+
gltf_buffer.resize(old_size + buffer_size);
1361+
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
1362+
bv->byte_length = buffer_size;
13551363
} break;
13561364
case GLTFAccessor::COMPONENT_TYPE_HALF_FLOAT: {
13571365
ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "glTF: Half float not supported yet.");
@@ -1372,10 +1380,11 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
13721380
dst_i++;
13731381
}
13741382
}
1375-
int64_t old_size = gltf_buffer.size();
1376-
gltf_buffer.resize(old_size + (buffer.size() * sizeof(int64_t)));
1377-
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(int64_t));
1378-
bv->byte_length = buffer.size() * sizeof(int64_t);
1383+
const int64_t old_size = gltf_buffer.size();
1384+
const size_t buffer_size = buffer.size() * sizeof(int64_t);
1385+
gltf_buffer.resize(old_size + buffer_size);
1386+
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
1387+
bv->byte_length = buffer_size;
13791388
} break;
13801389
case GLTFAccessor::COMPONENT_TYPE_UNSIGNED_LONG: {
13811390
Vector<uint64_t> buffer;
@@ -1393,10 +1402,11 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_
13931402
dst_i++;
13941403
}
13951404
}
1396-
int64_t old_size = gltf_buffer.size();
1397-
gltf_buffer.resize(old_size + (buffer.size() * sizeof(uint64_t)));
1398-
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer.size() * sizeof(uint64_t));
1399-
bv->byte_length = buffer.size() * sizeof(uint64_t);
1405+
const int64_t old_size = gltf_buffer.size();
1406+
const size_t buffer_size = buffer.size() * sizeof(uint64_t);
1407+
gltf_buffer.resize(old_size + buffer_size);
1408+
memcpy(gltf_buffer.ptrw() + old_size, buffer.ptrw(), buffer_size);
1409+
bv->byte_length = buffer_size;
14001410
} break;
14011411
}
14021412
ERR_FAIL_COND_V(buffer_end > bv->byte_length, ERR_INVALID_DATA);

0 commit comments

Comments
 (0)