]> O.S.I.I.S - jp/vkvg.git/commitdiff
don't store context with status_invalid, check surf pointer and status on ctx reuse
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 25 Jan 2022 11:32:47 +0000 (12:32 +0100)
committerj-p <jp_bruyere@hotmail.com>
Fri, 18 Feb 2022 20:09:23 +0000 (21:09 +0100)
src/vkvg_context.c

index 92c89b96b0123cafb6e7ee4ef91ffc0ebe26826d..dd845a28841410fb14cd4ac484bc5780df34958e 100644 (file)
@@ -92,6 +92,12 @@ VkvgContext vkvg_create(VkvgSurface surf)
        if (dev->cachedContextCount) {
                VkvgContext ctx = dev->cachedContext[--dev->cachedContextCount];
                ctx->pSurf = surf;
+
+               if (!surf || surf->status) {
+                       ctx->status = VKVG_STATUS_INVALID_SURFACE;
+                       return ctx;
+               }
+
                _init_ctx (ctx);
                _update_descriptor_set (ctx, surf->dev->emptyImg, ctx->dsSrc);
                _clear_path     (ctx);
@@ -107,6 +113,9 @@ VkvgContext vkvg_create(VkvgSurface surf)
                dev->status = VKVG_STATUS_NO_MEMORY;
                return NULL;
        }
+
+       ctx->pSurf = surf;
+
        if (!surf || surf->status) {
                ctx->status = VKVG_STATUS_INVALID_SURFACE;
                return ctx;
@@ -118,7 +127,6 @@ VkvgContext vkvg_create(VkvgSurface surf)
        ctx->sizePathes         = VKVG_PATHES_SIZE;
        ctx->renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
 
-       ctx->pSurf = surf;
        ctx->dev = surf->dev;
 
        _init_ctx (ctx);
@@ -284,7 +292,7 @@ void vkvg_destroy (VkvgContext ctx)
 
 #endif
 
-       if (ctx->dev->cachedContextCount < VKVG_MAX_CACHED_CONTEXT_COUNT) {
+       if (!ctx->status && ctx->dev->cachedContextCount < VKVG_MAX_CACHED_CONTEXT_COUNT) {
                ctx->dev->cachedContext[ctx->dev->cachedContextCount++] = ctx;
                _clear_context (ctx);
                ctx->references++;