Add UIGraphicsPush/PopContext to prevent lost reference during snapshot testing

Summary:
We're seeing sporadic "CGContext...: invalid context 0x..." error messages during snapshot runs of our product build. This also seems to happen sometimes when building RN, see for instance: https://www.google.nl/search?q=site%3Atravis-ci.org%2Ffacebook%2Freact-native%20CGContextSaveGState%20invalid%20context

Our guess is that at some point, the CGContextRef is autoreleased. We tried retaining the ref first, but eventually settled for pushing/popping the context as it never fails in our tests (retaining still causes seemingly unrelated failures).

We're not sure if we can provide a testplan for this change, as the FBSnapshotTestController is not tested separately.
Closes https://github.com/facebook/react-native/pull/8098

Differential Revision: D3431043

fbshipit-source-id: 61b9a7a849a020f6b8671d63781eed9418d409dc
This commit is contained in:
Albert Brand 2016-06-14 09:45:09 -07:00 committed by Facebook Github Bot 3
parent 668857a168
commit 420c07ef6f
1 changed files with 2 additions and 0 deletions

View File

@ -371,11 +371,13 @@ typedef NS_ENUM(NSUInteger, FBTestSnapshotFileNameType) {
CGContextRef context = UIGraphicsGetCurrentContext();
NSAssert1(context, @"Could not generate context for layer %@", layer);
UIGraphicsPushContext(context);
CGContextSaveGState(context);
{
[layer renderInContext:context];
}
CGContextRestoreGState(context);
UIGraphicsPopContext();
UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();