Skip to content

Commit

Permalink
fixing issue when creating multiple mlx application with leaks in the…
Browse files Browse the repository at this point in the history
… first one
  • Loading branch information
Kbz-8 committed Dec 28, 2023
1 parent 04ffce6 commit 5babfde
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 16 deletions.
19 changes: 17 additions & 2 deletions includes/mlx.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
/* Updated: 2023/12/20 00:57:15 by kiroussa ### ########.fr */
/* Updated: 2023/12/27 17:19:50 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -31,13 +31,15 @@ typedef enum
MLX_WINDOW_EVENT = 5
} mlx_event_type;


/**
* @brief Initializes the MLX internal application
*
* @return (void*) An opaque pointer to the internal MLX application or NULL (0x0) in case of error
*/
MLX_API void* mlx_init();


/**
* @brief Creates a new window
*
Expand All @@ -50,6 +52,7 @@ MLX_API void* mlx_init();
*/
MLX_API void* mlx_new_window(void* mlx, int w, int h, const char* title);


/**
* @brief Gives a function to be executed at each loop turn
*
Expand All @@ -59,9 +62,9 @@ MLX_API void* mlx_new_window(void* mlx, int w, int h, const char* title);
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/

MLX_API int mlx_loop_hook(void* mlx, int (*f)(void*), void* param);


/**
* @brief Starts the internal main loop
*
Expand All @@ -71,6 +74,7 @@ MLX_API int mlx_loop_hook(void* mlx, int (*f)(void*), void* param);
*/
MLX_API int mlx_loop(void* mlx);


/**
* @brief Ends the internal main loop
*
Expand All @@ -80,20 +84,23 @@ MLX_API int mlx_loop(void* mlx);
*/
MLX_API int mlx_loop_end(void* mlx);


/**
* @brief Shows mouse cursor
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_mouse_show();


/**
* @brief Hides mouse cursor
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_mouse_hide();


/**
* @brief Moves cursor to givent position
*
Expand All @@ -106,6 +113,7 @@ MLX_API int mlx_mouse_hide();
*/
MLX_API int mlx_mouse_move(void* mlx, void* win, int x, int y);


/**
* @brief Get cursor's position
*
Expand Down Expand Up @@ -160,6 +168,7 @@ MLX_API int mlx_pixel_put(void* mlx, void* win, int x, int y, int color);
*/
MLX_API void* mlx_new_image(void* mlx, int width, int height);


/**
* @brief Get image pixel data
*
Expand All @@ -180,6 +189,7 @@ MLX_API void* mlx_new_image(void* mlx, int width, int height);
*/
MLX_API int mlx_get_image_pixel(void* mlx, void* img, int x, int y);


/**
* @brief Set image pixel data
*
Expand All @@ -201,6 +211,7 @@ MLX_API int mlx_get_image_pixel(void* mlx, void* img, int x, int y);
*/
MLX_API void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color);


/**
* @brief Put image to the given window
*
Expand All @@ -214,6 +225,7 @@ MLX_API void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color);
*/
MLX_API int mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y);


/**
* @brief Destroys internal image
*
Expand All @@ -237,6 +249,7 @@ MLX_API int mlx_destroy_image(void* mlx, void* img);
*/
MLX_API void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height);


/**
* @brief Create a new image from a jpg file
*
Expand All @@ -249,6 +262,7 @@ MLX_API void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int*
*/
MLX_API void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height);


/**
* @brief Create a new image from a bmp file
*
Expand Down Expand Up @@ -288,6 +302,7 @@ MLX_API int mlx_string_put(void* mlx, void* win, int x, int y, int color, char*
*/
MLX_API void mlx_set_font(void* mlx, void* win, char* filepath);


/**
* @brief Loads a font to be used by `mlx_string_put` and scales it
*
Expand Down
4 changes: 2 additions & 2 deletions src/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2023/12/24 08:56:33 by kbz_8 ### ########.fr */
/* Updated: 2023/12/27 21:30:10 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -64,7 +64,7 @@ namespace mlx::core

void Application::destroyTexture(void* ptr)
{
vkDeviceWaitIdle(Render_Core::get().getDevice().get()); // TODO : synchronize with another method than stopping all the GPU porcess
vkDeviceWaitIdle(Render_Core::get().getDevice().get()); // TODO : synchronize with another method than stopping all the GPU process
Texture* texture = static_cast<Texture*>(ptr);
texture->destroy();
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:42:32 by maldavid #+# #+# */
/* Updated: 2023/12/11 19:46:57 by kbz_8 ### ########.fr */
/* Updated: 2023/12/27 17:21:07 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
2 changes: 1 addition & 1 deletion src/core/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
/* Updated: 2023/12/24 09:39:45 by kbz_8 ### ########.fr */
/* Updated: 2023/12/27 21:27:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
1 change: 0 additions & 1 deletion src/core/graphics.inl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
/* */
/* ************************************************************************** */

#include "renderer/images/texture.h"
#include <core/graphics.h>
#include <type_traits>

Expand Down
4 changes: 3 additions & 1 deletion src/platform/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
/* Updated: 2023/12/10 22:49:11 by kbz_8 ### ########.fr */
/* Updated: 2023/12/27 16:57:28 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -31,6 +31,8 @@ namespace mlx

MLX_Window::MLX_Window(std::size_t w, std::size_t h, const std::string& title) : _width(w), _height(h)
{
if(title.find("vvaas") != std::string::npos)
core::error::report(e_kind::message, "vvaas est mauvais");
_win = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN);
if(!_win)
core::error::report(e_kind::fatal_error, std::string("unable to open a new window, ") + SDL_GetError());
Expand Down
10 changes: 4 additions & 6 deletions src/renderer/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: kbz_8 <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/20 22:02:37 by kbz_8 #+# #+# */
/* Updated: 2023/12/16 19:14:15 by maldavid ### ########.fr */
/* Updated: 2023/12/27 21:31:04 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -17,11 +17,7 @@
#define VMA_STATIC_VULKAN_FUNCTIONS 0
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
#define VMA_VULKAN_VERSION 1002000
#ifdef DEBUG
#define VMA_ASSERT(expr) (static_cast<bool>(expr) ? void(0) : mlx::core::error::report(e_kind::fatal_error, "Graphics allocator : an assertion has been catched : '%s'", #expr))
#else
#define VMA_ASSERT(expr) ((void)0)
#endif
#define VMA_ASSERT(expr) ((void)0)
#define VMA_IMPLEMENTATION

#ifdef MLX_COMPILER_CLANG
Expand Down Expand Up @@ -177,5 +173,7 @@ namespace mlx
else if(_active_buffers_allocations != 0)
core::error::report(e_kind::error, "Graphics allocator : some MLX-dependant allocations were not freed before destroying the display (%d active allocations), please report, this should not happen", _active_buffers_allocations);
vmaDestroyAllocator(_allocator);
_active_buffers_allocations = 0;
_active_images_allocations = 0;
}
}
4 changes: 2 additions & 2 deletions src/renderer/core/vk_validation_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/19 14:05:25 by maldavid #+# #+# */
/* Updated: 2023/12/10 22:25:36 by kbz_8 ### ########.fr */
/* Updated: 2023/12/28 01:01:03 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -27,7 +27,7 @@ namespace mlx
VkDebugUtilsMessengerCreateInfoEXT createInfo;
populateDebugMessengerCreateInfo(createInfo);
if(createDebugUtilsMessengerEXT(&createInfo, nullptr) != VK_SUCCESS)
core::error::report(e_kind::error, "Vulkan : failed to set up debug messenger");
core::error::report(e_kind::warning, "Vulkan : failed to set up debug messenger");
#ifdef DEBUG
else
core::error::report(e_kind::message, "Vulkan : enabled validation layers");
Expand Down

0 comments on commit 5babfde

Please sign in to comment.