Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CT-DW: drawing with CoreText in bitmap context on background thread causes exception #1171

Closed
triplef opened this issue Oct 18, 2016 · 1 comment

Comments

@triplef
Copy link
Contributor

triplef commented Oct 18, 2016

Using the CT-DW branch (see #925), calling CTLineDraw() on a background thread to draw into a bitmap context causes the following exception:

E/WIL: E:\repo\WinObjC\WinObjC_Internal\Source\winmd2objc\ObjCUWP\ObjCUWP\projections\WindowsGraphicsDisplay.mm(46)\(null)!00C511D2: (caller: 0140B4AC) Objective-C Exception(1) tid(130) 80070490 Element not found.
    [+[WGDDisplayInformation getForCurrentView](_comInst->GetForCurrentView(unmarshalledReturn.GetAddressOf()))]

This can be reproduced by calling the following code on a background thread:

NSString *text = @"Test";

CGColorRef myCGColor = [UIColor blackColor].CGColor;
CTFontRef myCFFont = CTFontCreateWithName((__bridge CFStringRef)@"Helvetica", 20, NULL);
NSDictionary *attributesDict = @{(id)kCTFontAttributeName: (__bridge id)myCFFont,
                                 (id)kCTForegroundColorAttributeName: (__bridge id)myCGColor};

CGSize contextSize = CGSizeMake(1000, 1000);
CGColorSpaceRef colSpace = CGColorSpaceCreateDeviceRGB();
void*   bitmapData = malloc(contextSize.width*contextSize.height*4);
CGContextRef bitmapContext = CGBitmapContextCreate(bitmapData, contextSize.width, contextSize.height, 8, contextSize.width*4, colSpace, kCGImageAlphaPremultipliedFirst|kCGBitmapByteOrder32Host);
CGColorSpaceRelease(colSpace);

CGContextSetRGBFillColor(bitmapContext, 0, 0.0, 0.0, 1);
CGContextFillRect(bitmapContext, CGRectMake(0.0, 0.0, contextSize.width, contextSize.height));
CGContextSetRGBFillColor(bitmapContext, 1,1,1,1);
CGContextSetTextMatrix(bitmapContext, CGAffineTransformIdentity);

CFAttributedStringRef attrString = CFAttributedStringCreate(kCFAllocatorDefault, (__bridge CFStringRef)text, (__bridge CFDictionaryRef)attributesDict);
CTLineRef line = CTLineCreateWithAttributedString(attrString);
CGContextSetTextPosition(bitmapContext, 1, floorf(contextSize.height/5)+1);

CTLineDraw(line, bitmapContext);
@rajsesh
Copy link
Contributor

rajsesh commented Oct 18, 2016

@triplef thanks for trying this out early and providing feedback.

aballway added a commit that referenced this issue Oct 20, 2016
* Several bug fixes

* Address CR feedback

* Move dpi to method set

* More CR feedback


Handle edge case where a line is made up of white space, fix bug where trying to call CTRunDraw on a background thread would crash, and fix regression of not being able to have multiple colors in the same line.

Fixes #1130, #1109, and #1171
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants