From: Jean-Philippe Bruyère Date: Tue, 11 Jan 2022 13:55:16 +0000 (+0100) Subject: prevent trying to create surface with dim <= 0 X-Git-Tag: v0.3.0-beta~24 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=6e976deab1cf766d66f46d5e54da32f72d399916;p=jp%2Fvkvg.git prevent trying to create surface with dim <= 0 --- 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);