diff --git a/runtime/Sources/Core/Bridge.cpp b/runtime/Sources/Core/Bridge.cpp index e410b6c..21618f8 100644 --- a/runtime/Sources/Core/Bridge.cpp +++ b/runtime/Sources/Core/Bridge.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -224,17 +225,17 @@ extern "C" MLX_CHECK_APPLICATION_POINTER(mlx); if (filename == nullptr) { - mlx::Error("PNG loader: filename is NULL"); + mlx::Error("Image loader: filename is NULL"); return nullptr; } std::filesystem::path file(filename); - if( file.extension() != ".png" && + if(file.extension() != ".png" && file.extension() != ".jpg" && file.extension() != ".jpeg" && file.extension() != ".bmp" && file.extension() != ".dib") { - mlx::Error("PNG loader: not a valid file format '%'", filename); + mlx::Error("Image loader: not a valid file format '%'", filename); return nullptr; } return mlx->app->NewStbTexture(filename, width, height); diff --git a/runtime/Sources/Core/Memory.cpp b/runtime/Sources/Core/Memory.cpp index 9f8ee24..8989b3d 100644 --- a/runtime/Sources/Core/Memory.cpp +++ b/runtime/Sources/Core/Memory.cpp @@ -21,14 +21,14 @@ namespace mlx void* MemManager::AlignedMalloc(std::size_t alignment, std::size_t size) { - if(alignment < sizeof(void*)) - alignment = sizeof(void*); - if(size % alignment != 0) - size += alignment - (size % alignment); - #ifdef MLX_COMPILER_MSVC - void* ptr = _aligned_malloc(alignment, size); + void* ptr = _aligned_malloc(size, alignment); #else + if(alignment < sizeof(void*)) + alignment = sizeof(void*); + if(size % alignment != 0) + size += alignment - (size % alignment); + void* ptr = std::aligned_alloc(alignment, size); #endif if(ptr != nullptr) @@ -67,7 +67,7 @@ namespace mlx auto it = std::find_if(s_blocks.begin(), s_blocks.end(), [=](const Descriptor& rhs){ return ptr == rhs.ptr; }); #ifdef MLX_COMPILER_MSVC - void* ptr2 = _aligned_realloc(ptr, alignment, size); + void* ptr2 = _aligned_realloc(ptr, size, alignment); if(it != s_blocks.end()) s_blocks.erase(it); #else diff --git a/runtime/Sources/Renderer/Image.cpp b/runtime/Sources/Renderer/Image.cpp index 69fd9bc..6138f14 100644 --- a/runtime/Sources/Renderer/Image.cpp +++ b/runtime/Sources/Renderer/Image.cpp @@ -392,12 +392,12 @@ namespace mlx if(!std::filesystem::exists(file)) { - Error("Image: file not found %", file); + Error("Image loader: file not found %", file); return nullptr; } if(stbi_is_hdr(filename.c_str())) { - Error("Texture: unsupported image format from % (HDR image)", file); + Error("Image loader: unsupported image format from % (HDR image)", file); return nullptr; }