Skip to content

Commit

Permalink
no seriously fixed the graphics stack for GC
Browse files Browse the repository at this point in the history
  • Loading branch information
joshaber committed May 18, 2011
1 parent a8124db commit d9ebc37
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions UIKit/Classes/UIGraphics.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
#import <AppKit/AppKit.h>

typedef struct UISavedGraphicsContext_ {
NSGraphicsContext *context;
struct __strong UISavedGraphicsContext_ *previous;
NSGraphicsContext *context;
__strong struct UISavedGraphicsContext_ *previous;
} UISavedGraphicsContext;

static UISavedGraphicsContext *contextStack = NULL;

void UIGraphicsPushContext(CGContextRef ctx)
{
UISavedGraphicsContext *savedContext = (UISavedGraphicsContext *) malloc(sizeof(UISavedGraphicsContext));
savedContext->context = [[NSGraphicsContext currentContext] retain];
savedContext->context = CFRetain([NSGraphicsContext currentContext]);
savedContext->previous = contextStack;
contextStack = savedContext;
CGContextRetain(ctx);
Expand All @@ -54,11 +54,13 @@ void UIGraphicsPopContext()
UISavedGraphicsContext *popContext = contextStack;
if (popContext) {
CGContextRef oldContext = [[NSGraphicsContext currentContext] graphicsPort];
CGContextRelease(oldContext);

contextStack = popContext->previous;
[NSGraphicsContext setCurrentContext:popContext->context];
[popContext->context release];
CFRelease(popContext->context);
free(popContext), popContext = NULL;

CGContextRelease(oldContext);
}
}

Expand Down

0 comments on commit d9ebc37

Please sign in to comment.