Skip to content

Commit 3ba62d9

Browse files
committed
Fix blend render returning empty result
libass may return empty images, and 'blendResult' may become invalid (with zero height), leading to a runtime error when displaying. Noticed on 'Railgun S Karaoke Test' ~26.38s (after the first verse) with `dropAllAnimations` enabled.
1 parent 37ae5bc commit 3ba62d9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/SubtitleOctopus.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class SubtitleOctopus {
247247
int max_x = img->dst_x + img->w - 1, max_y = img->dst_y + img->h - 1;
248248
ASS_Image *cur;
249249
for (cur = img->next; cur != NULL; cur = cur->next) {
250+
if (cur->w == 0 || cur->h == 0) continue; // skip empty images
250251
if (cur->dst_x < min_x) min_x = cur->dst_x;
251252
if (cur->dst_y < min_y) min_y = cur->dst_y;
252253
int right = cur->dst_x + cur->w - 1;
@@ -255,8 +256,14 @@ class SubtitleOctopus {
255256
if (bottom > max_y) max_y = bottom;
256257
}
257258

258-
// make float buffer for blending
259259
int width = max_x - min_x + 1, height = max_y - min_y + 1;
260+
261+
if (width == 0 || height == 0) {
262+
// all images are empty
263+
return &m_blendResult;
264+
}
265+
266+
// make float buffer for blending
260267
float* buf = (float*)buffer_resize(&m_blend, sizeof(float) * width * height * 4, 0);
261268
if (buf == NULL) {
262269
printf("libass: error: cannot allocate buffer for blending");

0 commit comments

Comments
 (0)