adding error messages when using a corrupted window pointer, dropping SDL init responsability when running in sandbox

This commit is contained in:
Kbz-8
2023-12-21 00:28:53 +01:00
parent 6fb8932ba9
commit 79b01a5007
3 changed files with 29 additions and 2 deletions

View File

@@ -6,11 +6,12 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2023/12/15 20:51:41 by maldavid ### ########.fr */
/* Updated: 2023/12/21 00:17:54 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include "application.h"
#include <SDL2/SDL.h>
#include <renderer/images/texture.h>
#include <renderer/core/render_core.h>
#include <array>
@@ -20,8 +21,12 @@
namespace mlx::core
{
static bool __drop_sdl_responsability = false;
Application::Application() : _in(std::make_unique<Input>())
{
__drop_sdl_responsability = SDL_WasInit(SDL_INIT_VIDEO);
if(__drop_sdl_responsability) // is case the mlx is running in a sandbox like MacroUnitTester where SDL is already init
return;
SDL_SetMemoryFunctions(MemManager::malloc, MemManager::calloc, MemManager::realloc, MemManager::free);
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
error::report(e_kind::fatal_error, "SDL error : unable to init all subsystems : %s", SDL_GetError());
@@ -68,6 +73,8 @@ namespace mlx::core
Application::~Application()
{
if(__drop_sdl_responsability)
return;
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS);
SDL_Quit();
}