renderer-gl: Fix segfault when reading pixels

We should use the actual stride to create tmp pixmap.

Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
This commit is contained in:
Jeffy Chen 2023-12-20 10:48:18 +08:00
parent 623c7b5202
commit e454de5af3
1 changed files with 10 additions and 2 deletions

View File

@ -780,6 +780,7 @@ gl_renderer_do_read_pixels(struct gl_renderer *gr,
{
void *read_target;
pixman_image_t *tmp = NULL;
void *tmp_data = NULL;
assert(fmt->gl_type != 0);
assert(fmt->gl_format != 0);
@ -795,11 +796,17 @@ gl_renderer_do_read_pixels(struct gl_renderer *gr,
* glReadPixels() returns bottom row first. We need to
* read into a temporary buffer and y-flip it.
*/
tmp_data = malloc(stride * rect->height);
if (!tmp_data)
return false;
tmp = pixman_image_create_bits(fmt->pixman_format,
rect->width, rect->height,
NULL, 0);
if (!tmp)
tmp_data, stride);
if (!tmp) {
free(tmp_data);
return false;
}
read_target = pixman_image_get_data(tmp);
}
@ -834,6 +841,7 @@ gl_renderer_do_read_pixels(struct gl_renderer *gr,
pixman_image_unref(image);
pixman_image_unref(tmp);
free(tmp_data);
}
return true;