Skip to content

Commit

Permalink
Fix some crashes when showing screenshot previews
Browse files Browse the repository at this point in the history
  • Loading branch information
lhc70000 committed Aug 26, 2020
1 parent 6fc36c9 commit cc8b35a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions iina/ObjcUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ + (NSImage *)getImageFrom:(mpv_node *)image {
uint64_t height = list[1].u.int64;
uint64_t pixels = width * height;
uint8_t *pixel_array = list[4].u.ba->data;
uint8_t buffer[pixels * 4];
memcpy(buffer, pixel_array, pixels * 4);
size_t size = pixels * 4 * sizeof(uint8_t);
uint8_t *buffer = malloc(size);
memcpy(buffer, pixel_array, size);
int i;
// The pixel array mpv returns arrange color data as "B8G8R8X8",
// whereas CGImages's data provider needs RGBA, so swap each
Expand All @@ -101,7 +102,10 @@ + (NSImage *)getImageFrom:(mpv_node *)image {
CGColorSpaceCreateDeviceRGB(),
(CGBitmapInfo)kCGImageAlphaPremultipliedLast,
ref, nil, true, kCGRenderingIntentDefault);
return [[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize];

NSImage *nsImage = [[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize];
free(buffer);
return nsImage;
}

@end

0 comments on commit cc8b35a

Please sign in to comment.