Skip to content

Commit 31c0777

Browse files
committed
Merge pull request godotengine#100683 from Ivorforce/localvector-vector-conversion-typesafe-copy
Make `LocalVector` -> `Vector` automatic conversion safe for non-trivial types.
2 parents 9f42d1c + 0e32f3b commit 31c0777

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

core/templates/local_vector.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,16 @@ class LocalVector {
295295

296296
operator Vector<T>() const {
297297
Vector<T> ret;
298-
ret.resize(size());
298+
ret.resize(count);
299299
T *w = ret.ptrw();
300300
if (w) {
301-
memcpy(w, data, sizeof(T) * count);
301+
if constexpr (std::is_trivially_copyable_v<T>) {
302+
memcpy(w, data, sizeof(T) * count);
303+
} else {
304+
for (U i = 0; i < count; i++) {
305+
w[i] = data[i];
306+
}
307+
}
302308
}
303309
return ret;
304310
}

0 commit comments

Comments
 (0)