From 6e976deab1cf766d66f46d5e54da32f72d399916 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Tue, 11 Jan 2022 14:55:16 +0100 Subject: [PATCH] prevent trying to create surface with dim <= 0 --- src/vkvg_internal.h | 6 ++++++ src/vkvg_surface.c | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/vkvg_internal.h b/src/vkvg_internal.h index ec82a74..fa590c6 100644 --- a/src/vkvg_internal.h +++ b/src/vkvg_internal.h @@ -61,6 +61,12 @@ #define ROUND_DOWN(v,p) (floorf(v * p) / p) #define EQUF(a, b) (fabsf(a-b)<=FLT_EPSILON) +#ifndef MAX + #define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif +#ifndef MIN + #define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif #include "cross_os.h" #include "cross_mutex.h" diff --git a/src/vkvg_surface.c b/src/vkvg_surface.c index c059136..ed9a19c 100644 --- a/src/vkvg_surface.c +++ b/src/vkvg_surface.c @@ -29,6 +29,7 @@ #include "stb_image_write.h" #include "vkh_image.h" +#define max(x,y) void vkvg_surface_clear (VkvgSurface surf) { _clear_surface(surf, VK_IMAGE_ASPECT_STENCIL_BIT|VK_IMAGE_ASPECT_COLOR_BIT); } @@ -37,8 +38,8 @@ VkvgSurface vkvg_surface_create (VkvgDevice dev, uint32_t width, uint32_t height if (!surf) return NULL; - surf->width = width; - surf->height = height; + surf->width = MAX(1, width); + surf->height = MAX(1, height); surf->new = true;//used to clear all attacments on first render pass _create_surface_images (surf); @@ -77,8 +78,8 @@ VkvgSurface vkvg_surface_create_from_bitmap (VkvgDevice dev, unsigned char* img, if (!surf) return NULL; - surf->width = width; - surf->height = height; + surf->width = MAX(1, width); + surf->height = MAX(1, height); _create_surface_images (surf); -- 2.47.3