diff --git a/src/engine/core/default_allocator.cpp b/src/engine/core/default_allocator.cpp index b9a6f7ff26..da251990f3 100644 --- a/src/engine/core/default_allocator.cpp +++ b/src/engine/core/default_allocator.cpp @@ -23,6 +23,7 @@ namespace Lumix return realloc(ptr, size); } +#ifdef _WIN32 void* DefaultAllocator::allocate_aligned(size_t size, size_t align) { return _aligned_malloc(size, align); @@ -39,5 +40,35 @@ namespace Lumix { return _aligned_realloc(ptr, size, align); } +#else + void* DefaultAllocator::allocate_aligned(size_t size, size_t align) + { + return aligned_alloc(align, size); + } + + + void DefaultAllocator::deallocate_aligned(void* ptr) + { + free(ptr); + } + + + void* DefaultAllocator::reallocate_aligned(void* ptr, size_t size, size_t align) + { + // POSIX and glibc do not provide a way to realloc with alignment preservation + if (size == 0) { + free(ptr); + return nullptr; + } + void* newptr = aligned_alloc(align, size); + if (newptr == nullptr) { + return nullptr; + } + memcpy(newptr, ptr, size); + free(ptr); + return newptr; + } +#endif + } // ~namespace Lumix diff --git a/src/engine/core/geometry.cpp b/src/engine/core/geometry.cpp index 5dd4644697..71be582a1a 100644 --- a/src/engine/core/geometry.cpp +++ b/src/engine/core/geometry.cpp @@ -34,7 +34,7 @@ void Frustum::computeOrtho(const Vec3& position, center = (near_center + far_center) * 0.5f; float z_diff = far_distance - near_distance; - radius = sqrt(4 * width * width + 4 * height * height + z_diff * z_diff) * 0.5f; + radius = std::sqrt(4 * width * width + 4 * height * height + z_diff * z_diff) * 0.5f; this->position = position; } @@ -98,7 +98,7 @@ void Frustum::computePerspective(const Vec3& position, Vec3 corner2 = far_center + x * far_width + y * far_height; float size = (corner1 - corner2).length(); - size = Math::maximum(sqrt(far_width * far_width * 4 + far_height * far_height * 4), size); + size = Math::maximum(std::sqrt(far_width * far_width * 4 + far_height * far_height * 4), size); this->radius = size * 0.5f; this->position = position; this->direction = direction; diff --git a/src/engine/core/path_utils.cpp b/src/engine/core/path_utils.cpp index 4adf17977a..27ac919d25 100644 --- a/src/engine/core/path_utils.cpp +++ b/src/engine/core/path_utils.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "path_utils.h" #include "core/string.h" diff --git a/src/engine/core/string.cpp b/src/engine/core/string.cpp index fb5af622fe..b33e2bf856 100644 --- a/src/engine/core/string.cpp +++ b/src/engine/core/string.cpp @@ -27,7 +27,11 @@ int compareStringN(const char* lhs, const char* rhs, int length) int compareIStringN(const char* lhs, const char* rhs, int length) { +#ifdef _WIN32 return strnicmp(lhs, rhs, length); +#else + return strncasecmp(lhs, rhs, length); +#endif }