From 3249b05ae4af9cee482b09e3acb373a34430301c Mon Sep 17 00:00:00 2001 From: Henri Vasserman Date: Sun, 11 Apr 2021 23:29:54 +0300 Subject: [PATCH] add stride info --- xormod.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xormod.c b/xormod.c index 51d6c79..e1fdce5 100644 --- a/xormod.c +++ b/xormod.c @@ -18,6 +18,7 @@ typedef struct { int y2; int w; int h; + int s; SDL_Surface *surface; SDL_Texture *texture; uint32_t *pixels; @@ -37,11 +38,11 @@ static Picture *Picture_new(SDL_Renderer *rend, p->w = w; p->h = h; p->color = color; + p->s = (w + 7) / 8 * 8; - int stride = (w + 7) / 8 * 8; - p->pixels = malloc(stride * h * sizeof(uint32_t)); + p->pixels = malloc(p->s * h * sizeof(uint32_t)); p->surface = SDL_CreateRGBSurfaceWithFormatFrom( - p->pixels, w, h, 32, stride * sizeof(uint32_t), + p->pixels, w, h, 32, p->s * sizeof(uint32_t), SDL_PIXELFORMAT_RGBA32); Picture_render(p, rend);