Compare commits

...

2 Commits

Author SHA1 Message Date
ShiftyX1
f62574f588 update gitignore 2025-12-08 19:06:41 +03:00
Илья Глазунов
a28f630878 macOS issue with segfault fix 2025-12-01 20:39:44 +03:00
2 changed files with 26 additions and 4 deletions

11
.gitignore vendored
View File

@ -49,3 +49,14 @@ appimage-build/
# libs
/libs/
/vcpkg_installed/
CMakeCache.txt
cmake_install.cmake
CMakeFiles/
Makefile
compile_commands.json
VoxelEngine
libVoxelEngineSrc.a
vctest
.vctest/settings.toml

View File

@ -4,9 +4,12 @@
#include <mutex>
#include <vector>
#include <queue>
#include <new>
#if defined(_WIN32)
#include <malloc.h>
#else
#include <cstdlib>
#endif
namespace util {
@ -50,13 +53,21 @@ namespace util {
std::mutex mutex;
void allocateNew() {
std::unique_ptr<void, AlignedDeleter> ptr(
// Use posix_memalign on POSIX systems as aligned_alloc has stricter requirements
constexpr size_t alignment = alignof(T) < sizeof(void*) ? sizeof(void*) : alignof(T);
constexpr size_t size = sizeof(T);
void* rawPtr = nullptr;
#if defined(_WIN32)
_aligned_malloc(sizeof(T), alignof(T))
rawPtr = _aligned_malloc(size, alignment);
#else
std::aligned_alloc(alignof(T), sizeof(T))
if (posix_memalign(&rawPtr, alignment, size) != 0) {
rawPtr = nullptr;
}
#endif
);
if (rawPtr == nullptr) {
throw std::bad_alloc();
}
std::unique_ptr<void, AlignedDeleter> ptr(rawPtr);
freeObjects.push(ptr.get());
objects.push_back(std::move(ptr));
}