diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 48806fba7306..0329ace31305 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -318,9 +318,9 @@ int PacketPeerStream::get_output_buffer_max_size() const { } PacketPeerStream::PacketPeerStream() { - int rbsize = GLOBAL_GET("network/limits/packet_peer_stream/max_buffer_po2"); + int64_t rbsize = GLOBAL_GET("network/limits/packet_peer_stream/max_buffer_po2"); ring_buffer.resize(rbsize); - input_buffer.resize(1 << rbsize); - output_buffer.resize(1 << rbsize); + input_buffer.resize(int64_t(1) << rbsize); + output_buffer.resize(int64_t(1) << rbsize); } diff --git a/core/templates/cowdata.h b/core/templates/cowdata.h index 46d9797d6c38..d43cf8107fa8 100644 --- a/core/templates/cowdata.h +++ b/core/templates/cowdata.h @@ -46,7 +46,7 @@ class CharString; template class VMap; -SAFE_NUMERIC_TYPE_PUN_GUARANTEES(uint32_t) +SAFE_NUMERIC_TYPE_PUN_GUARANTEES(uint64_t) // Silence a false positive warning (see GH-52119). #if defined(__GNUC__) && !defined(__clang__) @@ -64,45 +64,71 @@ class CowData { template friend class VMap; +public: + typedef int64_t Size; + typedef uint64_t USize; + static constexpr USize MAX_INT = INT64_MAX; + private: + // Function to find the next power of 2 to an integer. + static _FORCE_INLINE_ USize next_po2(USize x) { + if (x == 0) { + return 0; + } + + --x; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + if (sizeof(USize) == 8) { + x |= x >> 32; + } + + return ++x; + } + + static constexpr USize ALLOC_PAD = sizeof(USize) * 2; // For size and atomic refcount. + mutable T *_ptr = nullptr; // internal helpers - _FORCE_INLINE_ SafeNumeric *_get_refcount() const { + _FORCE_INLINE_ SafeNumeric *_get_refcount() const { if (!_ptr) { return nullptr; } - return reinterpret_cast *>(_ptr) - 2; + return reinterpret_cast *>(_ptr) - 2; } - _FORCE_INLINE_ uint32_t *_get_size() const { + _FORCE_INLINE_ USize *_get_size() const { if (!_ptr) { return nullptr; } - return reinterpret_cast(_ptr) - 1; + return reinterpret_cast(_ptr) - 1; } - _FORCE_INLINE_ size_t _get_alloc_size(size_t p_elements) const { - return next_power_of_2(p_elements * sizeof(T)); + _FORCE_INLINE_ USize _get_alloc_size(USize p_elements) const { + return next_po2(p_elements * sizeof(T)); } - _FORCE_INLINE_ bool _get_alloc_size_checked(size_t p_elements, size_t *out) const { + _FORCE_INLINE_ bool _get_alloc_size_checked(USize p_elements, USize *out) const { if (unlikely(p_elements == 0)) { *out = 0; return true; } -#if defined(__GNUC__) - size_t o; - size_t p; +#if defined(__GNUC__) && defined(IS_32_BIT) + USize o; + USize p; if (__builtin_mul_overflow(p_elements, sizeof(T), &o)) { *out = 0; return false; } - *out = next_power_of_2(o); - if (__builtin_add_overflow(o, static_cast(32), &p)) { + *out = next_po2(o); + if (__builtin_add_overflow(o, static_cast(32), &p)) { return false; // No longer allocated here. } #else @@ -116,7 +142,7 @@ class CowData { void _unref(void *p_data); void _ref(const CowData *p_from); void _ref(const CowData &p_from); - uint32_t _copy_on_write(); + USize _copy_on_write(); public: void operator=(const CowData &p_from) { _ref(p_from); } @@ -130,8 +156,8 @@ class CowData { return _ptr; } - _FORCE_INLINE_ int size() const { - uint32_t *size = (uint32_t *)_get_size(); + _FORCE_INLINE_ Size size() const { + USize *size = (USize *)_get_size(); if (size) { return *size; } else { @@ -142,42 +168,42 @@ class CowData { _FORCE_INLINE_ void clear() { resize(0); } _FORCE_INLINE_ bool is_empty() const { return _ptr == nullptr; } - _FORCE_INLINE_ void set(int p_index, const T &p_elem) { + _FORCE_INLINE_ void set(Size p_index, const T &p_elem) { ERR_FAIL_INDEX(p_index, size()); _copy_on_write(); _ptr[p_index] = p_elem; } - _FORCE_INLINE_ T &get_m(int p_index) { + _FORCE_INLINE_ T &get_m(Size p_index) { CRASH_BAD_INDEX(p_index, size()); _copy_on_write(); return _ptr[p_index]; } - _FORCE_INLINE_ const T &get(int p_index) const { + _FORCE_INLINE_ const T &get(Size p_index) const { CRASH_BAD_INDEX(p_index, size()); return _ptr[p_index]; } template - Error resize(int p_size); + Error resize(Size p_size); - _FORCE_INLINE_ void remove_at(int p_index) { + _FORCE_INLINE_ void remove_at(Size p_index) { ERR_FAIL_INDEX(p_index, size()); T *p = ptrw(); - int len = size(); - for (int i = p_index; i < len - 1; i++) { + Size len = size(); + for (Size i = p_index; i < len - 1; i++) { p[i] = p[i + 1]; } resize(len - 1); } - Error insert(int p_pos, const T &p_val) { + Error insert(Size p_pos, const T &p_val) { ERR_FAIL_INDEX_V(p_pos, size() + 1, ERR_INVALID_PARAMETER); resize(size() + 1); - for (int i = (size() - 1); i > p_pos; i--) { + for (Size i = (size() - 1); i > p_pos; i--) { set(i, get(i - 1)); } set(p_pos, p_val); @@ -185,9 +211,9 @@ class CowData { return OK; } - int find(const T &p_val, int p_from = 0) const; - int rfind(const T &p_val, int p_from = -1) const; - int count(const T &p_val) const; + Size find(const T &p_val, Size p_from = 0) const; + Size rfind(const T &p_val, Size p_from = -1) const; + Size count(const T &p_val) const; _FORCE_INLINE_ CowData() {} _FORCE_INLINE_ ~CowData(); @@ -200,7 +226,7 @@ void CowData::_unref(void *p_data) { return; } - SafeNumeric *refc = _get_refcount(); + SafeNumeric *refc = _get_refcount(); if (refc->decrement() > 0) { return; // still in use @@ -208,35 +234,36 @@ void CowData::_unref(void *p_data) { // clean up if (!std::is_trivially_destructible::value) { - uint32_t *count = _get_size(); + USize *count = _get_size(); T *data = (T *)(count + 1); - for (uint32_t i = 0; i < *count; ++i) { + for (USize i = 0; i < *count; ++i) { // call destructors data[i].~T(); } } // free mem - Memory::free_static((uint8_t *)p_data, true); + Memory::free_static(((uint8_t *)p_data) - ALLOC_PAD, false); } template -uint32_t CowData::_copy_on_write() { +typename CowData::USize CowData::_copy_on_write() { if (!_ptr) { return 0; } - SafeNumeric *refc = _get_refcount(); + SafeNumeric *refc = _get_refcount(); - uint32_t rc = refc->get(); + USize rc = refc->get(); if (unlikely(rc > 1)) { /* in use by more than me */ - uint32_t current_size = *_get_size(); + USize current_size = *_get_size(); - uint32_t *mem_new = (uint32_t *)Memory::alloc_static(_get_alloc_size(current_size), true); + USize *mem_new = (USize *)Memory::alloc_static(_get_alloc_size(current_size) + ALLOC_PAD, false); + mem_new += 2; - new (mem_new - 2) SafeNumeric(1); //refcount + new (mem_new - 2) SafeNumeric(1); //refcount *(mem_new - 1) = current_size; //size T *_data = (T *)(mem_new); @@ -246,7 +273,7 @@ uint32_t CowData::_copy_on_write() { memcpy(mem_new, _ptr, current_size * sizeof(T)); } else { - for (uint32_t i = 0; i < current_size; i++) { + for (USize i = 0; i < current_size; i++) { memnew_placement(&_data[i], T(_ptr[i])); } } @@ -261,10 +288,10 @@ uint32_t CowData::_copy_on_write() { template template -Error CowData::resize(int p_size) { +Error CowData::resize(Size p_size) { ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER); - int current_size = size(); + Size current_size = size(); if (p_size == current_size) { return OK; @@ -278,27 +305,29 @@ Error CowData::resize(int p_size) { } // possibly changing size, copy on write - uint32_t rc = _copy_on_write(); + USize rc = _copy_on_write(); - size_t current_alloc_size = _get_alloc_size(current_size); - size_t alloc_size; + USize current_alloc_size = _get_alloc_size(current_size); + USize alloc_size; ERR_FAIL_COND_V(!_get_alloc_size_checked(p_size, &alloc_size), ERR_OUT_OF_MEMORY); if (p_size > current_size) { if (alloc_size != current_alloc_size) { if (current_size == 0) { // alloc from scratch - uint32_t *ptr = (uint32_t *)Memory::alloc_static(alloc_size, true); + USize *ptr = (USize *)Memory::alloc_static(alloc_size + ALLOC_PAD, false); + ptr += 2; ERR_FAIL_NULL_V(ptr, ERR_OUT_OF_MEMORY); *(ptr - 1) = 0; //size, currently none - new (ptr - 2) SafeNumeric(1); //refcount + new (ptr - 2) SafeNumeric(1); //refcount _ptr = (T *)ptr; } else { - uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true); + USize *_ptrnew = (USize *)Memory::realloc_static(((uint8_t *)_ptr) - ALLOC_PAD, alloc_size + ALLOC_PAD, false); ERR_FAIL_NULL_V(_ptrnew, ERR_OUT_OF_MEMORY); - new (_ptrnew - 2) SafeNumeric(rc); //refcount + _ptrnew += 2; + new (_ptrnew - 2) SafeNumeric(rc); //refcount _ptr = (T *)(_ptrnew); } @@ -307,7 +336,7 @@ Error CowData::resize(int p_size) { // construct the newly created elements if (!std::is_trivially_constructible::value) { - for (int i = *_get_size(); i < p_size; i++) { + for (Size i = *_get_size(); i < p_size; i++) { memnew_placement(&_ptr[i], T); } } else if (p_ensure_zero) { @@ -319,16 +348,17 @@ Error CowData::resize(int p_size) { } else if (p_size < current_size) { if (!std::is_trivially_destructible::value) { // deinitialize no longer needed elements - for (uint32_t i = p_size; i < *_get_size(); i++) { + for (USize i = p_size; i < *_get_size(); i++) { T *t = &_ptr[i]; t->~T(); } } if (alloc_size != current_alloc_size) { - uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true); + USize *_ptrnew = (USize *)Memory::realloc_static(((uint8_t *)_ptr) - ALLOC_PAD, alloc_size + ALLOC_PAD, false); ERR_FAIL_NULL_V(_ptrnew, ERR_OUT_OF_MEMORY); - new (_ptrnew - 2) SafeNumeric(rc); //refcount + _ptrnew += 2; + new (_ptrnew - 2) SafeNumeric(rc); //refcount _ptr = (T *)(_ptrnew); } @@ -340,14 +370,14 @@ Error CowData::resize(int p_size) { } template -int CowData::find(const T &p_val, int p_from) const { - int ret = -1; +typename CowData::Size CowData::find(const T &p_val, Size p_from) const { + Size ret = -1; if (p_from < 0 || size() == 0) { return ret; } - for (int i = p_from; i < size(); i++) { + for (Size i = p_from; i < size(); i++) { if (get(i) == p_val) { ret = i; break; @@ -358,8 +388,8 @@ int CowData::find(const T &p_val, int p_from) const { } template -int CowData::rfind(const T &p_val, int p_from) const { - const int s = size(); +typename CowData::Size CowData::rfind(const T &p_val, Size p_from) const { + const Size s = size(); if (p_from < 0) { p_from = s + p_from; @@ -368,7 +398,7 @@ int CowData::rfind(const T &p_val, int p_from) const { p_from = s - 1; } - for (int i = p_from; i >= 0; i--) { + for (Size i = p_from; i >= 0; i--) { if (get(i) == p_val) { return i; } @@ -377,9 +407,9 @@ int CowData::rfind(const T &p_val, int p_from) const { } template -int CowData::count(const T &p_val) const { - int amount = 0; - for (int i = 0; i < size(); i++) { +typename CowData::Size CowData::count(const T &p_val) const { + Size amount = 0; + for (Size i = 0; i < size(); i++) { if (get(i) == p_val) { amount++; } diff --git a/core/templates/ring_buffer.h b/core/templates/ring_buffer.h index d878894946ea..54148a59bf67 100644 --- a/core/templates/ring_buffer.h +++ b/core/templates/ring_buffer.h @@ -197,7 +197,7 @@ class RingBuffer { int old_size = size(); int new_size = 1 << p_power; int mask = new_size - 1; - data.resize(1 << p_power); + data.resize(int64_t(1) << int64_t(p_power)); if (old_size < new_size && read_pos > write_pos) { for (int i = 0; i < write_pos; i++) { data.write[(old_size + i) & mask] = data[i]; diff --git a/core/templates/vector.h b/core/templates/vector.h index d8bac0870f5b..361a7f56d564 100644 --- a/core/templates/vector.h +++ b/core/templates/vector.h @@ -48,7 +48,7 @@ template class VectorWriteProxy { public: - _FORCE_INLINE_ T &operator[](int p_index) { + _FORCE_INLINE_ T &operator[](typename CowData::Size p_index) { CRASH_BAD_INDEX(p_index, ((Vector *)(this))->_cowdata.size()); return ((Vector *)(this))->_cowdata.ptrw()[p_index]; @@ -61,6 +61,7 @@ class Vector { public: VectorWriteProxy write; + typedef typename CowData::Size Size; private: CowData _cowdata; @@ -70,9 +71,9 @@ class Vector { _FORCE_INLINE_ bool append(const T &p_elem) { return push_back(p_elem); } //alias void fill(T p_elem); - void remove_at(int p_index) { _cowdata.remove_at(p_index); } + void remove_at(Size p_index) { _cowdata.remove_at(p_index); } _FORCE_INLINE_ bool erase(const T &p_val) { - int idx = find(p_val); + Size idx = find(p_val); if (idx >= 0) { remove_at(idx); return true; @@ -87,17 +88,17 @@ class Vector { _FORCE_INLINE_ void clear() { resize(0); } _FORCE_INLINE_ bool is_empty() const { return _cowdata.is_empty(); } - _FORCE_INLINE_ T get(int p_index) { return _cowdata.get(p_index); } - _FORCE_INLINE_ const T &get(int p_index) const { return _cowdata.get(p_index); } - _FORCE_INLINE_ void set(int p_index, const T &p_elem) { _cowdata.set(p_index, p_elem); } - _FORCE_INLINE_ int size() const { return _cowdata.size(); } - Error resize(int p_size) { return _cowdata.resize(p_size); } - Error resize_zeroed(int p_size) { return _cowdata.template resize(p_size); } - _FORCE_INLINE_ const T &operator[](int p_index) const { return _cowdata.get(p_index); } - Error insert(int p_pos, T p_val) { return _cowdata.insert(p_pos, p_val); } - int find(const T &p_val, int p_from = 0) const { return _cowdata.find(p_val, p_from); } - int rfind(const T &p_val, int p_from = -1) const { return _cowdata.rfind(p_val, p_from); } - int count(const T &p_val) const { return _cowdata.count(p_val); } + _FORCE_INLINE_ T get(Size p_index) { return _cowdata.get(p_index); } + _FORCE_INLINE_ const T &get(Size p_index) const { return _cowdata.get(p_index); } + _FORCE_INLINE_ void set(Size p_index, const T &p_elem) { _cowdata.set(p_index, p_elem); } + _FORCE_INLINE_ Size size() const { return _cowdata.size(); } + Error resize(Size p_size) { return _cowdata.resize(p_size); } + Error resize_zeroed(Size p_size) { return _cowdata.template resize(p_size); } + _FORCE_INLINE_ const T &operator[](Size p_index) const { return _cowdata.get(p_index); } + Error insert(Size p_pos, T p_val) { return _cowdata.insert(p_pos, p_val); } + Size find(const T &p_val, Size p_from = 0) const { return _cowdata.find(p_val, p_from); } + Size rfind(const T &p_val, Size p_from = -1) const { return _cowdata.rfind(p_val, p_from); } + Size count(const T &p_val) const { return _cowdata.count(p_val); } void append_array(Vector p_other); @@ -109,7 +110,7 @@ class Vector { template void sort_custom(Args &&...args) { - int len = _cowdata.size(); + Size len = _cowdata.size(); if (len == 0) { return; } @@ -119,12 +120,12 @@ class Vector { sorter.sort(data, len); } - int bsearch(const T &p_value, bool p_before) { + Size bsearch(const T &p_value, bool p_before) { return bsearch_custom<_DefaultComparator>(p_value, p_before); } template - int bsearch_custom(const Value &p_value, bool p_before, Args &&...args) { + Size bsearch_custom(const Value &p_value, bool p_before, Args &&...args) { SearchArray search{ args... }; return search.bisect(ptrw(), size(), p_value, p_before); } @@ -134,7 +135,7 @@ class Vector { } void ordered_insert(const T &p_val) { - int i; + Size i; for (i = 0; i < _cowdata.size(); i++) { if (p_val < operator[](i)) { break; @@ -157,28 +158,28 @@ class Vector { return ret; } - Vector slice(int p_begin, int p_end = INT_MAX) const { + Vector slice(Size p_begin, Size p_end = CowData::MAX_INT) const { Vector result; - const int s = size(); + const Size s = size(); - int begin = CLAMP(p_begin, -s, s); + Size begin = CLAMP(p_begin, -s, s); if (begin < 0) { begin += s; } - int end = CLAMP(p_end, -s, s); + Size end = CLAMP(p_end, -s, s); if (end < 0) { end += s; } ERR_FAIL_COND_V(begin > end, result); - int result_size = end - begin; + Size result_size = end - begin; result.resize(result_size); const T *const r = ptr(); T *const w = result.ptrw(); - for (int i = 0; i < result_size; ++i) { + for (Size i = 0; i < result_size; ++i) { w[i] = r[begin + i]; } @@ -186,11 +187,11 @@ class Vector { } bool operator==(const Vector &p_arr) const { - int s = size(); + Size s = size(); if (s != p_arr.size()) { return false; } - for (int i = 0; i < s; i++) { + for (Size i = 0; i < s; i++) { if (operator[](i) != p_arr[i]) { return false; } @@ -199,11 +200,11 @@ class Vector { } bool operator!=(const Vector &p_arr) const { - int s = size(); + Size s = size(); if (s != p_arr.size()) { return true; } - for (int i = 0; i < s; i++) { + for (Size i = 0; i < s; i++) { if (operator[](i) != p_arr[i]) { return true; } @@ -280,7 +281,7 @@ class Vector { Error err = _cowdata.resize(p_init.size()); ERR_FAIL_COND(err); - int i = 0; + Size i = 0; for (const T &element : p_init) { _cowdata.set(i++, element); } @@ -292,7 +293,7 @@ class Vector { template void Vector::reverse() { - for (int i = 0; i < size() / 2; i++) { + for (Size i = 0; i < size() / 2; i++) { T *p = ptrw(); SWAP(p[i], p[size() - i - 1]); } @@ -300,13 +301,13 @@ void Vector::reverse() { template void Vector::append_array(Vector p_other) { - const int ds = p_other.size(); + const Size ds = p_other.size(); if (ds == 0) { return; } - const int bs = size(); + const Size bs = size(); resize(bs + ds); - for (int i = 0; i < ds; ++i) { + for (Size i = 0; i < ds; ++i) { ptrw()[bs + i] = p_other[i]; } } @@ -323,7 +324,7 @@ bool Vector::push_back(T p_elem) { template void Vector::fill(T p_elem) { T *p = ptrw(); - for (int i = 0; i < size(); i++) { + for (Size i = 0; i < size(); i++) { p[i] = p_elem; } } diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 03836985f3a2..90f7e7b44a7a 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -666,7 +666,7 @@ struct _VariantCall { CharString cs; cs.resize(p_instance->size() + 1); memcpy(cs.ptrw(), r, p_instance->size()); - cs[p_instance->size()] = 0; + cs[(int)p_instance->size()] = 0; s = cs.get_data(); } diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index f6633f8bf687..79969619bf86 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1375,7 +1375,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code return GDScriptCodeGenerator::Address(); } - codegen.script->lambda_info.insert(function, { lambda->captures.size(), lambda->use_self }); + codegen.script->lambda_info.insert(function, { (int)lambda->captures.size(), lambda->use_self }); gen->write_lambda(result, function, captures, lambda->use_self); for (int i = 0; i < captures.size(); i++) { diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index 7b03ac74d64b..1a8c22cc11a1 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -655,7 +655,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } bool exit_ok = false; bool awaited = false; - int variant_address_limits[ADDR_TYPE_MAX] = { _stack_size, _constant_count, p_instance ? p_instance->members.size() : 0 }; + int variant_address_limits[ADDR_TYPE_MAX] = { _stack_size, _constant_count, p_instance ? (int)p_instance->members.size() : 0 }; #endif Variant *variant_addresses[ADDR_TYPE_MAX] = { stack, _constants_ptr, p_instance ? p_instance->members.ptrw() : nullptr }; diff --git a/modules/lightmapper_rd/lightmapper_rd.cpp b/modules/lightmapper_rd/lightmapper_rd.cpp index 4746ffb79b96..d2fe8a7534e2 100644 --- a/modules/lightmapper_rd/lightmapper_rd.cpp +++ b/modules/lightmapper_rd/lightmapper_rd.cpp @@ -1711,7 +1711,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d push_constant.ray_from = i * max_rays; push_constant.ray_to = MIN((i + 1) * max_rays, int32_t(push_constant.ray_count)); rd->compute_list_set_push_constant(compute_list, &push_constant, sizeof(PushConstant)); - rd->compute_list_dispatch(compute_list, Math::division_round_up(probe_positions.size(), 64), 1, 1); + rd->compute_list_dispatch(compute_list, Math::division_round_up((int)probe_positions.size(), 64), 1, 1); rd->compute_list_end(); //done rd->submit(); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs index d5d9404ed1bc..c806263edb57 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs @@ -474,7 +474,7 @@ public readonly IntPtr Buffer public readonly unsafe int Size { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _ptr != IntPtr.Zero ? *((int*)_ptr - 1) : 0; + get => _ptr != IntPtr.Zero ? (int)(*((ulong*)_ptr - 1)) : 0; } } @@ -725,7 +725,7 @@ private struct VariantVector public readonly unsafe int Size { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _ptr != null ? *((int*)_ptr - 1) : 0; + get => _ptr != null ? (int)(*((ulong*)_ptr - 1)) : 0; } } @@ -875,7 +875,7 @@ public readonly unsafe byte* Buffer public readonly unsafe int Size { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _ptr != null ? *((int*)_ptr - 1) : 0; + get => _ptr != null ? (int)(*((ulong*)_ptr - 1)) : 0; } } @@ -939,7 +939,7 @@ public readonly unsafe long* Buffer public readonly unsafe int Size { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _ptr != null ? *((int*)_ptr - 1) : 0; + get => _ptr != null ? (int)(*((ulong*)_ptr - 1)) : 0; } } @@ -971,7 +971,7 @@ public readonly unsafe float* Buffer public readonly unsafe int Size { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _ptr != null ? *((int*)_ptr - 1) : 0; + get => _ptr != null ? (int)(*((ulong*)_ptr - 1)) : 0; } } @@ -1003,7 +1003,7 @@ public readonly unsafe double* Buffer public readonly unsafe int Size { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _ptr != null ? *((int*)_ptr - 1) : 0; + get => _ptr != null ? (int)(*((ulong*)_ptr - 1)) : 0; } } @@ -1035,7 +1035,7 @@ public readonly unsafe godot_string* Buffer public readonly unsafe int Size { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _ptr != null ? *((int*)_ptr - 1) : 0; + get => _ptr != null ? (int)(*((ulong*)_ptr - 1)) : 0; } } @@ -1067,7 +1067,7 @@ public readonly unsafe Vector2* Buffer public readonly unsafe int Size { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _ptr != null ? *((int*)_ptr - 1) : 0; + get => _ptr != null ? (int)(*((ulong*)_ptr - 1)) : 0; } } @@ -1099,7 +1099,7 @@ public readonly unsafe Vector3* Buffer public readonly unsafe int Size { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _ptr != null ? *((int*)_ptr - 1) : 0; + get => _ptr != null ? (int)(*((ulong*)_ptr - 1)) : 0; } } @@ -1131,7 +1131,7 @@ public readonly unsafe Color* Buffer public readonly unsafe int Size { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _ptr != null ? *((int*)_ptr - 1) : 0; + get => _ptr != null ? (int)(*((ulong*)_ptr - 1)) : 0; } } diff --git a/servers/rendering/renderer_rd/storage_rd/light_storage.cpp b/servers/rendering/renderer_rd/storage_rd/light_storage.cpp index 21c6425a8783..150e82c25c5b 100644 --- a/servers/rendering/renderer_rd/storage_rd/light_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/light_storage.cpp @@ -1988,7 +1988,7 @@ void LightStorage::shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits for (int i = 0; i < 4; i++) { //clear subdivisions shadow_atlas->quadrants[i].shadows.clear(); - shadow_atlas->quadrants[i].shadows.resize(1 << shadow_atlas->quadrants[i].subdivision); + shadow_atlas->quadrants[i].shadows.resize(int64_t(1) << int64_t(shadow_atlas->quadrants[i].subdivision)); } //erase shadow atlas reference from lights