adding check to texture pointers

This commit is contained in:
2024-01-26 11:59:57 +01:00
parent 528867bc7b
commit 1dd24f687c
4 changed files with 32 additions and 23 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
/* Updated: 2024/01/19 05:34:23 by maldavid ### ########.fr */
/* Updated: 2024/01/26 11:59:34 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2024/01/20 08:21:37 by maldavid ### ########.fr */
/* Updated: 2024/01/26 11:56:34 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -86,12 +86,20 @@ namespace mlx::core
vkDeviceWaitIdle(Render_Core::get().getDevice().get()); // TODO : synchronize with another method than waiting for GPU to be idle
if(ptr == nullptr)
{
core::error::report(e_kind::error, "wrong texture (NULL)");
core::error::report(e_kind::error, "invalid image ptr (NULL)");
return;
}
else if(std::find_if(_textures.begin(), _textures.end(), [=](const Texture& texture)
{
return &texture == ptr;
}) == _textures.end())
{
core::error::report(e_kind::error, "invalid image ptr");
return;
}
Texture* texture = static_cast<Texture*>(ptr);
if(!texture->isInit())
core::error::report(e_kind::error, "trying to destroy a texture");
core::error::report(e_kind::error, "trying to destroy a texture that has already been destroyed");
else
texture->destroy();
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
/* Updated: 2024/01/18 14:59:47 by maldavid ### ########.fr */
/* Updated: 2024/01/26 11:26:54 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,9 +15,7 @@
#include <list>
#include <memory>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <core/errors.h>

View File

@@ -22,7 +22,22 @@
{ \
core::error::report(e_kind::error, "invalid window ptr"); \
return; \
} else {}\
} else {}
#define CHECK_IMAGE_PTR(img, retval) \
if(img == nullptr) \
{ \
core::error::report(e_kind::error, "invalid image ptr (NULL)"); \
retval; \
} \
else if(std::find_if(_textures.begin(), _textures.end(), [=](const Texture& texture) \
{ \
return &texture == img; \
}) == _textures.end()) \
{ \
core::error::report(e_kind::error, "invalid image ptr"); \
retval; \
} else {}
namespace mlx::core
{
@@ -140,11 +155,7 @@ namespace mlx::core
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
if(img == nullptr)
{
core::error::report(e_kind::error, "wrong texture (NULL)");
return;
}
CHECK_IMAGE_PTR(img, return);
Texture* texture = static_cast<Texture*>(img);
if(!texture->isInit())
core::error::report(e_kind::error, "trying to put a texture that has been destroyed");
@@ -155,11 +166,7 @@ namespace mlx::core
int Application::getTexturePixel(void* img, int x, int y)
{
MLX_PROFILE_FUNCTION();
if(img == nullptr)
{
core::error::report(e_kind::error, "wrong texture (NULL)");
return 0;
}
CHECK_IMAGE_PTR(img, return 0);
Texture* texture = static_cast<Texture*>(img);
if(!texture->isInit())
{
@@ -172,11 +179,7 @@ namespace mlx::core
void Application::setTexturePixel(void* img, int x, int y, uint32_t color)
{
MLX_PROFILE_FUNCTION();
if(img == nullptr)
{
core::error::report(e_kind::error, "wrong texture (NULL)");
return;
}
CHECK_IMAGE_PTR(img, return);
Texture* texture = static_cast<Texture*>(img);
if(!texture->isInit())
core::error::report(e_kind::error, "trying to set a pixel on texture that has been destroyed");