Skip to content

Commit

Permalink
Fix for issue #26
Browse files Browse the repository at this point in the history
Fix for random crashing caused by the CADisplayLink during animations.
  • Loading branch information
NinjaKittenProductions committed May 17, 2014
1 parent 407dad9 commit c17a6fc
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,18 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - [self getAnimationStartTime]) / [self getAnimationDuration];
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[self setProgress:[self getAnimationToValue]];
});
[self setDisplayLink:nil];
[self setProgress:[self getAnimationToValue]];
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[self setProgress:([self getAnimationFromValue] + dt * ([self getAnimationToValue] - [self getAnimationFromValue]))];
});

//Set progress
[self setProgress:[self getAnimationFromValue] + dt * ([self getAnimationToValue] - [self getAnimationFromValue])];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
});
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewBorderedBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
});
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewFilteredImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
});
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
});
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewLetterpress.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
});
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewMetro.m
Original file line number Diff line number Diff line change
Expand Up @@ -251,24 +251,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self showProgress];
});
[super setProgress:_animationToValue animated:NO];
[self showProgress];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self showProgress];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self showProgress];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewPie.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
});
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewRadiative.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
});
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewRing.m
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
});
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewSegmentedBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
});
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewSegmentedRing.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
});
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];

});
}
Expand Down
16 changes: 6 additions & 10 deletions Classes/ProgressViews/M13ProgressViewStripedBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,24 +230,20 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated

- (void)animateProgress:(CADisplayLink *)displayLink
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat dt = (displayLink.timestamp - _animationStartTime) / self.animationDuration;
if (dt >= 1.0) {
//Order is important! Otherwise concurrency will cause errors, because setProgress: will detect an animation in progress and try to stop it by itself. Once over one, set to actual progress amount. Animation is over.
[self.displayLink removeFromRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
self.displayLink = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
});
[super setProgress:_animationToValue animated:NO];
[self setNeedsDisplay];
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];
});
//Set progress
[super setProgress:_animationFromValue + dt * (_animationToValue - _animationFromValue) animated:YES];
[self setNeedsDisplay];

});
}
Expand Down
Loading

0 comments on commit c17a6fc

Please sign in to comment.