From 6641495b354a572872ce6fcf896cbf451638af78 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Wed, 1 Apr 2015 12:43:46 +0200 Subject: [PATCH] Fix a potential crash on 10.6.8 in the preview generation. --- MP42/MP42PreviewGenerator.m | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/MP42/MP42PreviewGenerator.m b/MP42/MP42PreviewGenerator.m index de22751..17764aa 100644 --- a/MP42/MP42PreviewGenerator.m +++ b/MP42/MP42PreviewGenerator.m @@ -28,7 +28,7 @@ } + (NSArray *)generatePreviewImagesQTKitFromChapters:(NSArray *)chapters andFile:(NSURL *)file { - __block QTMovie * qtMovie; + __block QTMovie *qtMovie; // QTMovie objects must always be create on the main thread. NSDictionary *movieAttributes = @{QTMovieURLAttribute: file, @@ -42,30 +42,33 @@ dispatch_sync(dispatch_get_main_queue(), ^{ qtMovie = [[QTMovie alloc] initWithAttributes:movieAttributes error:nil]; }); - } - else + } else { qtMovie = [[QTMovie alloc] initWithAttributes:movieAttributes error:nil]; + } - if (!qtMovie) + if (!qtMovie) { return nil; + } - for (QTTrack *qtTrack in [qtMovie tracksOfMediaType:@"sbtl"]) + for (QTTrack *qtTrack in [qtMovie tracksOfMediaType:@"sbtl"]) { [qtTrack setAttribute:@NO forKey:QTTrackEnabledAttribute]; + } NSDictionary *attributes = [NSDictionary dictionaryWithObject:QTMovieFrameImageTypeNSImage forKey:QTMovieFrameImageType]; - NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:[chapters count]]; + NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:chapters.count]; for (MP42TextSample *chapter in chapters) { QTTime chapterTime = { - [chapter timestamp] + 1500, // Add a short offset, hopefully we will get a better image - 1000, // if there is a fade + chapter.timestamp + 1500, // Add a short offset, hopefully we will get a better image + 1000, // if there is a fade 0 }; NSImage *frame = [qtMovie frameImageAtTime:chapterTime withAttributes:attributes error:nil]; - if (images) + if (frame) { [images addObject:frame]; + } } // Release the movie, we don't want to keep it open while we are writing in it using another library. @@ -74,9 +77,9 @@ dispatch_sync(dispatch_get_main_queue(), ^{ [qtMovie release]; }); - } - else + } else { [qtMovie release]; + } return [images autorelease]; }