<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I tried your calls to NSFont in Objective-C, and it also crashes. Looking at the stack trace, I see that it crashes in CFCharacterSetHasMemberInPlane. I see documentation for&nbsp;<span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 12px;" class="">thePlane</span>&nbsp;parameter of this function says:</div><div class=""><br class=""></div><div class=""><span style="font-size: 12px;" class=""><span style="color: rgb(0, 132, 0); font-family: Menlo;" class="">The valid value range is from 0 to 16.</span><span style="color: rgb(0, 132, 0); font-family: Menlo;" class="">&nbsp; </span><span style="color: rgb(0, 132, 0); font-family: Menlo;" class="">If the value is outside of the valid&nbsp;</span><span style="color: rgb(0, 132, 0); font-family: Menlo;" class="">plane number range, the behavior is undefined.</span></span></div><div class=""><br class=""></div>I guess randomly crashing counts as undefined behavior.<div class="">While it would be great if this function was more robust, Apple is definitely saying Don’t Do That.</div><div class=""><br class=""></div><div class="">Doug Hill<br class=""><div class=""><a href="https://github.com/djfitz/SFFontFeatures" class="">https://github.com/djfitz/SFFontFeatures</a></div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 13, 2017, at 9:42 AM, Jens Persson via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">PS</div>There are only 17 planes in the (current?) Unicode standard, but I'm assuming that the CharacterSet.hasMember(inPlane:) shouldn't (randomly?) crash for UInt8 values other than 0 ... 16?<div class="">It also seems strange that it reproducibly crashes or not depending on which specific font I use.</div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Jun 13, 2017 at 4:00 PM, Jens Persson <span dir="ltr" class="">&lt;<a href="mailto:jens@bitcycle.com" target="_blank" class="">jens@bitcycle.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="">The below program demonstrates a possible bug that I encountered.</div>Can anyone else reproduce my results (as explained in the comments)?<div class="">If so, is it a Swift or Cocoa bug (I haven't tried it in Objective C)?</div><div class=""><div class=""><br class=""></div><div class="">import AppKit</div><div class=""><br class=""></div><div class="">extension NSFont {</div><div class="">&nbsp; &nbsp; var planesWithMembers: [UInt8] {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; return (UInt8(0) ... UInt8(255)).filter {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The follwing line will crash (EXC_BAD_ACCESS) for some fonts:</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; coveredCharacterSet.hasMember(<wbr class="">inPlane: $0)</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // I have tested it with Xcode 8.3.3 and Xcode 9 beta 1, both</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Swift 3 and 4, and they all reproduce the crash.</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // macOS 10.12.5</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div><div class=""><br class=""></div><div class="">// Examples that will not cause the crash:</div><div class="">// let fontName = "AlBayan"</div><div class="">// let fontName = "AppleBraille"</div><div class="">// let fontName = "Chalkboard"</div><div class="">// let fontName = "Helvetica"</div><div class="">// let fontName = "Zapfino"</div><div class=""><br class=""></div><div class="">// Examples that will cause the crash:</div><div class="">// let fontName = "AppleColorEmoji"</div><div class="">// let fontName = "AppleSymbols"</div><div class="">let fontName = "Baskerville"</div><div class="">// let fontName = "Geneva"</div><div class="">// let fontName = "SnellRoundhand"</div><div class=""><br class=""></div><div class="">let font = NSFont(name: fontName, size: 12)!</div><div class="">let result = font.planesWithMembers</div><div class="">print("Planes that contains members:", result)</div></div><div class=""><br class=""></div></div>
</blockquote></div><br class=""></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></div></body></html>