fixing memory leaks, begenning xmake support to build on windows

This commit is contained in:
2023-12-07 23:19:56 +01:00
parent 53c0f08bc1
commit 854a074cac
14 changed files with 1306 additions and 17 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
/* Updated: 2023/11/25 10:12:36 by maldavid ### ########.fr */
/* Updated: 2023/12/07 23:05:05 by kbz_8 ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,8 +26,8 @@ extern "C"
mlx::core::error::report(e_kind::error, "MLX cannot be initialized multiple times");
return NULL;
}
mlx::Render_Core::get().init();
mlx::core::Application* app = new mlx::core::Application;
mlx::Render_Core::get().init();
if(app == nullptr)
mlx::core::error::report(e_kind::fatal_error, "Tout a pété");
init = true;

47
src/core/memory.cpp git.filemode.normal_file
View File

@@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* memory.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kbz_8 </var/spool/mail/kbz_8> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/07 16:32:01 by kbz_8 #+# #+# */
/* Updated: 2023/12/07 16:43:56 by kbz_8 ### ########.fr */
/* */
/* ************************************************************************** */
#include <core/memory.h>
#include <core/errors.h>
#include <algorithm>
#include <stdlib.h>
namespace mlx
{
void* MemManager::alloc(std::size_t size)
{
void* ptr = std::malloc(size);
if(ptr != nullptr)
_blocks.push_back(ptr);
return ptr;
}
void MemManager::free(void* ptr)
{
auto it = std::find(_blocks.begin(), _blocks.end(), ptr);
if(it == _blocks.end())
{
core::error::report(e_kind::error, "Memory Manager : trying to free a pointer not allocated by the memory manager");
return;
}
std::free(*it);
_blocks.erase(it);
}
MemManager::~MemManager()
{
std::for_each(_blocks.begin(), _blocks.end(), [](void* ptr)
{
std::free(ptr);
});
}
}

38
src/core/memory.h git.filemode.normal_file
View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* memory.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kbz_8 </var/spool/mail/kbz_8> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/07 16:31:51 by kbz_8 #+# #+# */
/* Updated: 2023/12/07 16:37:15 by kbz_8 ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_MEMORY__
#define __MLX_MEMORY__
#include <utils/singleton.h>
#include <list>
namespace mlx
{
class MemManager : public Singleton<MemManager>
{
friend class Singleton<MemManager>;
public:
void* alloc(std::size_t size);
void free(void* ptr);
private:
MemManager() = default;
~MemManager();
private:
std::list<void*> _blocks;
};
}
#endif