diff options
| author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2023-02-21 12:47:40 +0200 |
|---|---|---|
| committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2023-02-21 15:32:26 +0200 |
| commit | ba4b50118d26642a4e3603a5687b0cc1ca093396 (patch) | |
| tree | 9213f1b29ddfd9266eec6cbf12d82a89d14979f2 /include/godot_cpp/core | |
| parent | 2f07eb07eea9e5ef3a6e9f8707f08cec77db579f (diff) | |
| download | redot-cpp-ba4b50118d26642a4e3603a5687b0cc1ca093396.tar.gz | |
Fix incorrect memory allocation in release builds.
Co-authored-by: lightyears <lightyears1998@hotmail.com>
Diffstat (limited to 'include/godot_cpp/core')
| -rw-r--r-- | include/godot_cpp/core/memory.hpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/include/godot_cpp/core/memory.hpp b/include/godot_cpp/core/memory.hpp index 25f87ec..55cdb8b 100644 --- a/include/godot_cpp/core/memory.hpp +++ b/include/godot_cpp/core/memory.hpp @@ -40,6 +40,10 @@ #include <type_traits> +#ifndef PAD_ALIGN +#define PAD_ALIGN 16 //must always be greater than this at much +#endif + void *operator new(size_t p_size, const char *p_description); ///< operator new that takes a description and uses MemoryStaticPool void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)); ///< operator new that takes a description and uses MemoryStaticPool void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description); ///< operator new that takes a description and uses a pointer to the preallocated memory @@ -64,9 +68,9 @@ class Memory { Memory(); public: - static void *alloc_static(size_t p_bytes); - static void *realloc_static(void *p_memory, size_t p_bytes); - static void free_static(void *p_ptr); + static void *alloc_static(size_t p_bytes, bool p_pad_align = false); + static void *realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align = false); + static void free_static(void *p_ptr, bool p_pad_align = false); }; _ALWAYS_INLINE_ void postinitialize_handler(void *) {} @@ -140,7 +144,7 @@ T *memnew_arr_template(size_t p_elements, const char *p_descr = "") { same strategy used by std::vector, and the Vector class, so it should be safe.*/ size_t len = sizeof(T) * p_elements; - uint64_t *mem = (uint64_t *)Memory::alloc_static(len); + uint64_t *mem = (uint64_t *)Memory::alloc_static(len, true); T *failptr = nullptr; // Get rid of a warning. ERR_FAIL_COND_V(!mem, failptr); *(mem - 1) = p_elements; @@ -169,7 +173,7 @@ void memdelete_arr(T *p_class) { } } - Memory::free_static(ptr); + Memory::free_static(ptr, true); } struct _GlobalNil { |
