Skip to content

Commit edeaff7

Browse files
authored
adding check to texture pointers (#46)
2 parents 1b50e12 + 2d57584 commit edeaff7

17 files changed

+5566
-1166
lines changed

example/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
9-
/* Updated: 2024/01/19 05:34:23 by maldavid ### ########.fr */
9+
/* Updated: 2024/01/26 11:59:34 by maldavid ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

src/core/application.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
9-
/* Updated: 2024/01/20 08:21:37 by maldavid ### ########.fr */
9+
/* Updated: 2024/01/26 11:56:34 by maldavid ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -86,12 +86,20 @@ namespace mlx::core
8686
vkDeviceWaitIdle(Render_Core::get().getDevice().get()); // TODO : synchronize with another method than waiting for GPU to be idle
8787
if(ptr == nullptr)
8888
{
89-
core::error::report(e_kind::error, "wrong texture (NULL)");
89+
core::error::report(e_kind::error, "invalid image ptr (NULL)");
90+
return;
91+
}
92+
else if(std::find_if(_textures.begin(), _textures.end(), [=](const Texture& texture)
93+
{
94+
return &texture == ptr;
95+
}) == _textures.end())
96+
{
97+
core::error::report(e_kind::error, "invalid image ptr");
9098
return;
9199
}
92100
Texture* texture = static_cast<Texture*>(ptr);
93101
if(!texture->isInit())
94-
core::error::report(e_kind::error, "trying to destroy a texture");
102+
core::error::report(e_kind::error, "trying to destroy a texture that has already been destroyed");
95103
else
96104
texture->destroy();
97105
}

src/core/application.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
9-
/* Updated: 2024/01/18 14:59:47 by maldavid ### ########.fr */
9+
/* Updated: 2024/01/26 11:26:54 by maldavid ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -15,9 +15,7 @@
1515

1616
#include <list>
1717
#include <memory>
18-
#include <string>
1918
#include <vector>
20-
#include <utility>
2119
#include <functional>
2220

2321
#include <core/errors.h>

src/core/application.inl

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,22 @@
2222
{ \
2323
core::error::report(e_kind::error, "invalid window ptr"); \
2424
return; \
25-
} else {}\
25+
} else {}
26+
27+
#define CHECK_IMAGE_PTR(img, retval) \
28+
if(img == nullptr) \
29+
{ \
30+
core::error::report(e_kind::error, "invalid image ptr (NULL)"); \
31+
retval; \
32+
} \
33+
else if(std::find_if(_textures.begin(), _textures.end(), [=](const Texture& texture) \
34+
{ \
35+
return &texture == img; \
36+
}) == _textures.end()) \
37+
{ \
38+
core::error::report(e_kind::error, "invalid image ptr"); \
39+
retval; \
40+
} else {}
2641

2742
namespace mlx::core
2843
{
@@ -140,11 +155,7 @@ namespace mlx::core
140155
{
141156
MLX_PROFILE_FUNCTION();
142157
CHECK_WINDOW_PTR(win);
143-
if(img == nullptr)
144-
{
145-
core::error::report(e_kind::error, "wrong texture (NULL)");
146-
return;
147-
}
158+
CHECK_IMAGE_PTR(img, return);
148159
Texture* texture = static_cast<Texture*>(img);
149160
if(!texture->isInit())
150161
core::error::report(e_kind::error, "trying to put a texture that has been destroyed");
@@ -155,11 +166,7 @@ namespace mlx::core
155166
int Application::getTexturePixel(void* img, int x, int y)
156167
{
157168
MLX_PROFILE_FUNCTION();
158-
if(img == nullptr)
159-
{
160-
core::error::report(e_kind::error, "wrong texture (NULL)");
161-
return 0;
162-
}
169+
CHECK_IMAGE_PTR(img, return 0);
163170
Texture* texture = static_cast<Texture*>(img);
164171
if(!texture->isInit())
165172
{
@@ -172,11 +179,7 @@ namespace mlx::core
172179
void Application::setTexturePixel(void* img, int x, int y, uint32_t color)
173180
{
174181
MLX_PROFILE_FUNCTION();
175-
if(img == nullptr)
176-
{
177-
core::error::report(e_kind::error, "wrong texture (NULL)");
178-
return;
179-
}
182+
CHECK_IMAGE_PTR(img, return);
180183
Texture* texture = static_cast<Texture*>(img);
181184
if(!texture->isInit())
182185
core::error::report(e_kind::error, "trying to set a pixel on texture that has been destroyed");

third_party/vulkan/vulkan.cppm

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,6 @@ export namespace VULKAN_HPP_NAMESPACE
643643
using VULKAN_HPP_NAMESPACE::HeadlessSurfaceCreateFlagBitsEXT;
644644
using VULKAN_HPP_NAMESPACE::HeadlessSurfaceCreateFlagsEXT;
645645

646-
//=== VK_EXT_line_rasterization ===
647-
using VULKAN_HPP_NAMESPACE::LineRasterizationModeEXT;
648-
649646
//=== VK_KHR_pipeline_executable_properties ===
650647
using VULKAN_HPP_NAMESPACE::PipelineExecutableStatisticFormatKHR;
651648

@@ -839,6 +836,10 @@ export namespace VULKAN_HPP_NAMESPACE
839836
//=== VK_MSFT_layered_driver ===
840837
using VULKAN_HPP_NAMESPACE::LayeredDriverUnderlyingApiMSFT;
841838

839+
//=== VK_KHR_line_rasterization ===
840+
using VULKAN_HPP_NAMESPACE::LineRasterizationModeEXT;
841+
using VULKAN_HPP_NAMESPACE::LineRasterizationModeKHR;
842+
842843
//=== VK_KHR_calibrated_timestamps ===
843844
using VULKAN_HPP_NAMESPACE::TimeDomainEXT;
844845
using VULKAN_HPP_NAMESPACE::TimeDomainKHR;
@@ -1742,10 +1743,18 @@ export namespace VULKAN_HPP_NAMESPACE
17421743
using VULKAN_HPP_NAMESPACE::AMDDeviceCoherentMemoryExtensionName;
17431744
using VULKAN_HPP_NAMESPACE::AMDDeviceCoherentMemorySpecVersion;
17441745

1746+
//=== VK_KHR_dynamic_rendering_local_read ===
1747+
using VULKAN_HPP_NAMESPACE::KHRDynamicRenderingLocalReadExtensionName;
1748+
using VULKAN_HPP_NAMESPACE::KHRDynamicRenderingLocalReadSpecVersion;
1749+
17451750
//=== VK_EXT_shader_image_atomic_int64 ===
17461751
using VULKAN_HPP_NAMESPACE::EXTShaderImageAtomicInt64ExtensionName;
17471752
using VULKAN_HPP_NAMESPACE::EXTShaderImageAtomicInt64SpecVersion;
17481753

1754+
//=== VK_KHR_shader_quad_control ===
1755+
using VULKAN_HPP_NAMESPACE::KHRShaderQuadControlExtensionName;
1756+
using VULKAN_HPP_NAMESPACE::KHRShaderQuadControlSpecVersion;
1757+
17491758
//=== VK_KHR_spirv_1_4 ===
17501759
using VULKAN_HPP_NAMESPACE::KHRSpirv14ExtensionName;
17511760
using VULKAN_HPP_NAMESPACE::KHRSpirv14SpecVersion;
@@ -2227,6 +2236,10 @@ export namespace VULKAN_HPP_NAMESPACE
22272236
using VULKAN_HPP_NAMESPACE::ARMShaderCorePropertiesExtensionName;
22282237
using VULKAN_HPP_NAMESPACE::ARMShaderCorePropertiesSpecVersion;
22292238

2239+
//=== VK_KHR_shader_subgroup_rotate ===
2240+
using VULKAN_HPP_NAMESPACE::KHRShaderSubgroupRotateExtensionName;
2241+
using VULKAN_HPP_NAMESPACE::KHRShaderSubgroupRotateSpecVersion;
2242+
22302243
//=== VK_ARM_scheduling_controls ===
22312244
using VULKAN_HPP_NAMESPACE::ARMSchedulingControlsExtensionName;
22322245
using VULKAN_HPP_NAMESPACE::ARMSchedulingControlsSpecVersion;
@@ -2276,6 +2289,10 @@ export namespace VULKAN_HPP_NAMESPACE
22762289
using VULKAN_HPP_NAMESPACE::GOOGLESurfacelessQueryExtensionName;
22772290
using VULKAN_HPP_NAMESPACE::GOOGLESurfacelessQuerySpecVersion;
22782291

2292+
//=== VK_KHR_shader_maximal_reconvergence ===
2293+
using VULKAN_HPP_NAMESPACE::KHRShaderMaximalReconvergenceExtensionName;
2294+
using VULKAN_HPP_NAMESPACE::KHRShaderMaximalReconvergenceSpecVersion;
2295+
22792296
//=== VK_EXT_image_compression_control_swapchain ===
22802297
using VULKAN_HPP_NAMESPACE::EXTImageCompressionControlSwapchainExtensionName;
22812298
using VULKAN_HPP_NAMESPACE::EXTImageCompressionControlSwapchainSpecVersion;
@@ -2427,6 +2444,14 @@ export namespace VULKAN_HPP_NAMESPACE
24272444
using VULKAN_HPP_NAMESPACE::KHRVertexAttributeDivisorExtensionName;
24282445
using VULKAN_HPP_NAMESPACE::KHRVertexAttributeDivisorSpecVersion;
24292446

2447+
//=== VK_KHR_load_store_op_none ===
2448+
using VULKAN_HPP_NAMESPACE::KHRLoadStoreOpNoneExtensionName;
2449+
using VULKAN_HPP_NAMESPACE::KHRLoadStoreOpNoneSpecVersion;
2450+
2451+
//=== VK_KHR_shader_float_controls2 ===
2452+
using VULKAN_HPP_NAMESPACE::KHRShaderFloatControls2ExtensionName;
2453+
using VULKAN_HPP_NAMESPACE::KHRShaderFloatControls2SpecVersion;
2454+
24302455
#if defined( VK_USE_PLATFORM_SCREEN_QNX )
24312456
//=== VK_QNX_external_memory_screen_buffer ===
24322457
using VULKAN_HPP_NAMESPACE::QNXExternalMemoryScreenBufferExtensionName;
@@ -2437,10 +2462,22 @@ export namespace VULKAN_HPP_NAMESPACE
24372462
using VULKAN_HPP_NAMESPACE::MSFTLayeredDriverExtensionName;
24382463
using VULKAN_HPP_NAMESPACE::MSFTLayeredDriverSpecVersion;
24392464

2465+
//=== VK_KHR_index_type_uint8 ===
2466+
using VULKAN_HPP_NAMESPACE::KHRIndexTypeUint8ExtensionName;
2467+
using VULKAN_HPP_NAMESPACE::KHRIndexTypeUint8SpecVersion;
2468+
2469+
//=== VK_KHR_line_rasterization ===
2470+
using VULKAN_HPP_NAMESPACE::KHRLineRasterizationExtensionName;
2471+
using VULKAN_HPP_NAMESPACE::KHRLineRasterizationSpecVersion;
2472+
24402473
//=== VK_KHR_calibrated_timestamps ===
24412474
using VULKAN_HPP_NAMESPACE::KHRCalibratedTimestampsExtensionName;
24422475
using VULKAN_HPP_NAMESPACE::KHRCalibratedTimestampsSpecVersion;
24432476

2477+
//=== VK_KHR_shader_expect_assume ===
2478+
using VULKAN_HPP_NAMESPACE::KHRShaderExpectAssumeExtensionName;
2479+
using VULKAN_HPP_NAMESPACE::KHRShaderExpectAssumeSpecVersion;
2480+
24442481
//=== VK_KHR_maintenance6 ===
24452482
using VULKAN_HPP_NAMESPACE::KHRMaintenance6ExtensionName;
24462483
using VULKAN_HPP_NAMESPACE::KHRMaintenance6SpecVersion;
@@ -3531,9 +3568,17 @@ export namespace VULKAN_HPP_NAMESPACE
35313568
//=== VK_AMD_device_coherent_memory ===
35323569
using VULKAN_HPP_NAMESPACE::PhysicalDeviceCoherentMemoryFeaturesAMD;
35333570

3571+
//=== VK_KHR_dynamic_rendering_local_read ===
3572+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceDynamicRenderingLocalReadFeaturesKHR;
3573+
using VULKAN_HPP_NAMESPACE::RenderingAttachmentLocationInfoKHR;
3574+
using VULKAN_HPP_NAMESPACE::RenderingInputAttachmentIndexInfoKHR;
3575+
35343576
//=== VK_EXT_shader_image_atomic_int64 ===
35353577
using VULKAN_HPP_NAMESPACE::PhysicalDeviceShaderImageAtomicInt64FeaturesEXT;
35363578

3579+
//=== VK_KHR_shader_quad_control ===
3580+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceShaderQuadControlFeaturesKHR;
3581+
35373582
//=== VK_EXT_memory_budget ===
35383583
using VULKAN_HPP_NAMESPACE::PhysicalDeviceMemoryBudgetPropertiesEXT;
35393584

@@ -3589,17 +3634,9 @@ export namespace VULKAN_HPP_NAMESPACE
35893634
//=== VK_EXT_headless_surface ===
35903635
using VULKAN_HPP_NAMESPACE::HeadlessSurfaceCreateInfoEXT;
35913636

3592-
//=== VK_EXT_line_rasterization ===
3593-
using VULKAN_HPP_NAMESPACE::PhysicalDeviceLineRasterizationFeaturesEXT;
3594-
using VULKAN_HPP_NAMESPACE::PhysicalDeviceLineRasterizationPropertiesEXT;
3595-
using VULKAN_HPP_NAMESPACE::PipelineRasterizationLineStateCreateInfoEXT;
3596-
35973637
//=== VK_EXT_shader_atomic_float ===
35983638
using VULKAN_HPP_NAMESPACE::PhysicalDeviceShaderAtomicFloatFeaturesEXT;
35993639

3600-
//=== VK_EXT_index_type_uint8 ===
3601-
using VULKAN_HPP_NAMESPACE::PhysicalDeviceIndexTypeUint8FeaturesEXT;
3602-
36033640
//=== VK_EXT_extended_dynamic_state ===
36043641
using VULKAN_HPP_NAMESPACE::PhysicalDeviceExtendedDynamicStateFeaturesEXT;
36053642

@@ -3986,6 +4023,9 @@ export namespace VULKAN_HPP_NAMESPACE
39864023
//=== VK_ARM_shader_core_properties ===
39874024
using VULKAN_HPP_NAMESPACE::PhysicalDeviceShaderCorePropertiesARM;
39884025

4026+
//=== VK_KHR_shader_subgroup_rotate ===
4027+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceShaderSubgroupRotateFeaturesKHR;
4028+
39894029
//=== VK_ARM_scheduling_controls ===
39904030
using VULKAN_HPP_NAMESPACE::DeviceQueueShaderCoreControlCreateInfoARM;
39914031
using VULKAN_HPP_NAMESPACE::PhysicalDeviceSchedulingControlsFeaturesARM;
@@ -4038,6 +4078,9 @@ export namespace VULKAN_HPP_NAMESPACE
40384078
//=== VK_NV_linear_color_attachment ===
40394079
using VULKAN_HPP_NAMESPACE::PhysicalDeviceLinearColorAttachmentFeaturesNV;
40404080

4081+
//=== VK_KHR_shader_maximal_reconvergence ===
4082+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceShaderMaximalReconvergenceFeaturesKHR;
4083+
40414084
//=== VK_EXT_image_compression_control_swapchain ===
40424085
using VULKAN_HPP_NAMESPACE::PhysicalDeviceImageCompressionControlSwapchainFeaturesEXT;
40434086

@@ -4220,6 +4263,9 @@ export namespace VULKAN_HPP_NAMESPACE
42204263
using VULKAN_HPP_NAMESPACE::VertexInputBindingDivisorDescriptionEXT;
42214264
using VULKAN_HPP_NAMESPACE::VertexInputBindingDivisorDescriptionKHR;
42224265

4266+
//=== VK_KHR_shader_float_controls2 ===
4267+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceShaderFloatControls2FeaturesKHR;
4268+
42234269
#if defined( VK_USE_PLATFORM_SCREEN_QNX )
42244270
//=== VK_QNX_external_memory_screen_buffer ===
42254271
using VULKAN_HPP_NAMESPACE::ExternalFormatQNX;
@@ -4232,10 +4278,25 @@ export namespace VULKAN_HPP_NAMESPACE
42324278
//=== VK_MSFT_layered_driver ===
42334279
using VULKAN_HPP_NAMESPACE::PhysicalDeviceLayeredDriverPropertiesMSFT;
42344280

4281+
//=== VK_KHR_index_type_uint8 ===
4282+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceIndexTypeUint8FeaturesEXT;
4283+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceIndexTypeUint8FeaturesKHR;
4284+
4285+
//=== VK_KHR_line_rasterization ===
4286+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceLineRasterizationFeaturesEXT;
4287+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceLineRasterizationFeaturesKHR;
4288+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceLineRasterizationPropertiesEXT;
4289+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceLineRasterizationPropertiesKHR;
4290+
using VULKAN_HPP_NAMESPACE::PipelineRasterizationLineStateCreateInfoEXT;
4291+
using VULKAN_HPP_NAMESPACE::PipelineRasterizationLineStateCreateInfoKHR;
4292+
42354293
//=== VK_KHR_calibrated_timestamps ===
42364294
using VULKAN_HPP_NAMESPACE::CalibratedTimestampInfoEXT;
42374295
using VULKAN_HPP_NAMESPACE::CalibratedTimestampInfoKHR;
42384296

4297+
//=== VK_KHR_shader_expect_assume ===
4298+
using VULKAN_HPP_NAMESPACE::PhysicalDeviceShaderExpectAssumeFeaturesKHR;
4299+
42394300
//=== VK_KHR_maintenance6 ===
42404301
using VULKAN_HPP_NAMESPACE::BindDescriptorBufferEmbeddedSamplersInfoEXT;
42414302
using VULKAN_HPP_NAMESPACE::BindDescriptorSetsInfoKHR;

0 commit comments

Comments
 (0)