Fix that SDAnimatedImageView initWithImage will skip the initialize logic and crash

This commit is contained in:
DreamPiggy 2019-05-15 20:26:39 +08:00
parent ce5103bedf
commit 63c0794ad8
2 changed files with 25 additions and 0 deletions

View File

@ -62,6 +62,7 @@ static NSUInteger SDDeviceFreeMemory() {
#else
@property (nonatomic, strong) CADisplayLink *displayLink;
#endif
@property (nonatomic, assign) BOOL hasInitialized;
@end
@ -123,6 +124,11 @@ static NSUInteger SDDeviceFreeMemory() {
- (void)commonInit
{
if (self.hasInitialized) {
return;
}
self.hasInitialized = YES;
self.shouldCustomLoopCount = NO;
self.shouldIncrementalLoad = YES;
self.lock = dispatch_semaphore_create(1);
@ -183,6 +189,11 @@ static NSUInteger SDDeviceFreeMemory() {
return;
}
// Check has initlized
if (!self.hasInitialized) {
[self commonInit];
}
// Check Progressive rendering
[self updateIsProgressiveWithImage:image];

View File

@ -156,6 +156,20 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
#endif
}
- (void)test12AnimatedImageViewInitWithImage {
// Test that -[SDAnimatedImageView initWithImage:] this convenience initializer not crash
SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testAPNGPData]];
SDAnimatedImageView *imageView;
#if SD_UIKIT
imageView = [[SDAnimatedImageView alloc] initWithImage:image];
#else
if (@available(macOS 10.12, *)) {
imageView = [SDAnimatedImageView imageViewWithImage:image];
}
#endif
expect(imageView.image).equal(image);
}
- (void)test20AnimatedImageViewRendering {
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView rendering"];
SDAnimatedImageView *imageView = [[SDAnimatedImageView alloc] init];