| Ticket UUID: | de579935a92b3084ee86d0067fbef88142856f56 | |||
| Title: | Scid vs PC CGPathCreateWithRoundedRect Assertion fails | |||
| Type: | Bug | Version: | 8.6 and 8.7 head | |
| Submitter: | stevenaaus | Created on: | 2019-10-27 03:45:30 | |
| Subsystem: | 16. [scrollbar] | Assigned To: | nobody | |
| Priority: | 5 Medium | Severity: | Important | |
| Status: | Closed | Last Modified: | 2019-10-30 22:18:04 | |
| Resolution: | Fixed | Closed By: | marc_culler | |
| Closed on: | 2019-10-30 22:18:04 | |||
| Description: |
I'm getting some regular text window assertion fails for our app on macOS (El Cap). (https://sourceforge.net/projects/scidvspc/) The failure is
Assertion failed: (corner_width >= 0 && 2 * corner_width <= CGRectGetWidth(rect)), function CGPathRef CGPathCreateWithRoundedRect(CGRect, CGFloat, CGFloat, const CGAffineTransform * _Nullable), file Paths/CGPath.cc, line 189.
Abort trap: 6 (core dumped)
(The failing version is ff76eece. The oldest passing version i have tested is 8140ebf0)
We have several text widgets that are affected at various times.
It's not hard to reproducet - In the entrybox at the bottom of the startup windows, type
foreach i [array names helpText] {helpWindow $i}
which will fly through our help files. (PS, new build entrybox's do not seem to allow me to Command-v to paste text anymore. ?8140ebf0 pastes fine too)
I'm having a little trouble making a Dev framework. The old GNUMakefiles used to make both , but now leaves "build/tk/Development/Tk.framework/" mostly empty.
How do i build a Dev framework for a proper BT ? Thanks Steven
/Users/admin/scidvspc/sa$lldb -c /cores/core.67234
(lldb) target create --core "/cores/core.67234"
bt allCore file '/cores/core.67234' (x86_64) was loaded.
(lldb) bt all
* thread #1: tid = 0x0000, 0x00007fff95ebcf06 libsystem_kernel.dylib`__pthread_kill + 10, stop reason = signal SIGSTOP
* frame #0: 0x00007fff95ebcf06 libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x00007fff897804ec libsystem_pthread.dylib`pthread_kill + 90
frame #2: 0x00007fff8c91f6df libsystem_c.dylib`abort + 129
frame #3: 0x00007fff8c8e6dd8 libsystem_c.dylib`__assert_rtn + 321
frame #4: 0x00007fff973ff47b CoreGraphics`CGPathCreateWithRoundedRect + 1076
frame #5: 0x000000010ff98ccf Tk`___lldb_unnamed_symbol2178$$Tk + 1327
frame #6: 0x000000010ff9823d Tk`___lldb_unnamed_symbol2176$$Tk + 1117
frame #7: 0x000000010fdb2d36 Tcl`TclServiceIdle + 77
frame #8: 0x000000010fd95f17 Tcl`Tcl_DoOneEvent + 350
frame #9: 0x000000010ff9ed19 Tk`___lldb_unnamed_symbol2225$$Tk + 233
frame #10: 0x000000010ff9e6ba Tk`___lldb_unnamed_symbol2221$$Tk + 458
frame #11: 0x00007fff907e5cd2 AppKit`-[NSView _drawRect:clip:] + 3626
frame #12: 0x00007fff9083dcad AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:]
| |||
| User Comments: |
marc_culler (claiming to be Marc Culler) added on 2019-10-30 22:18:04:
Thank you, François! I will merge the alternate branch and close this ticket. fvogel added on 2019-10-30 20:19:39: This alternate proposal sounds better to me. Less surprises to the user who sets -width, less clamping behavior to document, simply adjust the radius of the rounded corners if the scrollbar width is too small. Looks nice and a brilliant idea! marc_culler (claiming to be Marc Culler) added on 2019-10-30 14:39:03: I have an alternate proposal for how to fix this in branch bug-de579935a9-alt. (It also does not raise an exception in ScidvsMac.) It does not set any minimum width. It just adjusts the radius of the thumb corners to be either 4, when the thumb is at least 8 pixels wide, or (width >> 1) when the thumb is too skinny for a radius 4 corner. @stevenaaus and @fvogel: please help me decide which is better. My rationale is that one of the perceived advantages of Tk over Ttk is that it allows people much more freedom to create their own odd looking widgets. So why not allow scrollbars which do not look like they belong in the Aqua theme? marc_culler (claiming to be Marc Culler) added on 2019-10-29 21:46:57: No, I hadn't tried it. Sorry, I was in the middle of something and didn't want to stop to build core-8-6-branch at that moment. But now I have tried it and you are absolutely correct. Core graphics just draws a skinny thumb with no complaints and no assertion failures. Here is the best I can do for an explanation: CGPathCreateWithRoundedRect sometimes raises that assertion exception and sometimes does not. I know that I had seen the exception long ago -- that was why I added the CHECK_RADIUS macro. But after running your script I remembered that I had also seen the skinny thumb before. Whether it raises the exception must depend on the state of the graphics context. Or something. I guess these are the joys of dealing with proprietary software. We will never know what actually triggers the exception. But we do have very strong evidence that it sometimes happens and causes Tk to crash. So I think that means that we really do want to make sure the assertion never fails. fvogel added on 2019-10-29 20:25:58: Did you actually try? I did. Example, try this in core-8-6-branch:
package require Tk
frame .f
text .f.t -wrap none -yscrollcommand {.f.s set} -xscrollcommand {.sh set}
set s [string repeat "abcdefghijklmnopqrstuvwxyz " 50]
for {set i 1} {$i < 100} {incr i} {
.f.t insert end [string range $s $i end]\n
}
scrollbar .f.s -command {.f.t yview}
scrollbar .sh -orient horizontal -command {.f.t xview}
pack .f.t .f.s -side left -fill y -expand true
pack .f .sh -fill x -expand true
.sh configure -width ; # returns 15
.sh configure -width 6 ; # works!! thumb is drawn
.f.s configure -width 6 ; # works!!
marc_culler (claiming to be Marc Culler) added on 2019-10-29 20:07:01: My guess is that you did not do anything to cause the thumb to be drawn. If it had been drawn you would have seen something weird. It definitely would not fit into a 6 pixel trough. fvogel added on 2019-10-29 19:59:53: Yeah, I like this much much better than the previous two proposals. Thanks! Perhaps we should add a mention in the scrollbar man page that the user-specified -width will be clamped to a minimum on some platforms. This is [ae3ad0074b] and should prevent us from being pestered with new bug reports telling us that -width cannot be set according to the programmer's wills :-). One last thing that is slightly inconsistent with the picture I have for this ticket: From your diagnostic of the core issue at play here, I concluded that (in the current core-8-6-branch) incantating e.g. marc_culler (claiming to be Marc Culler) added on 2019-10-29 13:44:45: I think I found the right way to do this. Too bad no one told me about TkpConfigureScrollbar :^( @fvogel: Can you please review one more time? fvogel added on 2019-10-29 12:40:39: Yes, [4b9a7620] is much better IMO. Still, if the user configures manually the -width after the scrollbar creation, the scrollbar will disappear on the mac. Is this what we want or should the width rather be clamped to its min size in ConfigureScrollbar()? That is what I had in mind but perhaps its not desirable. marc_culler (claiming to be Marc Culler) added on 2019-10-29 12:28:08: OK, I found a way to set the minWidth of a Tk scrollbar without making it user-configurable. @fvogel: Does this look OK to you? marc_culler (claiming to be Marc Culler) added on 2019-10-29 11:23:21: François, I would much prefer that the minwidth of a scrollbar on a mac *not* be user configurable. If it is made any smaller the thumb will disappear. So let me ask you your own question: do we have to make it user-configurable? Can we avoid that somehow? fvogel added on 2019-10-29 07:55:30: Marc, regarding [6fd10bcd2c893194], do we really need to add this as a new platform-specific user-visible option for the scrollbar? Such a change would require a TIP I think, couldn't we check that minsize without exposing it as a user option? stevenaaus added on 2019-10-29 03:58:18: Cheers - it works now i think. I tested the -width 12 on your widget, but my testing must have been amiss. > if you use ttk widgets whenever possible your app will look better. Also, you would not have run into this problem Sorry, but i don't agree with this at all. "Mainline" Scid has widely adopted ttk widgets and they have some serious issues, generally focus related, and ttk's hit and mis look and feel often clashes with the oft necessary tk:: widgets which must be alongside them. Additionally, this bug has nothing to do with tk, but is solely about the Cocoa port. marc_culler (claiming to be Marc Culler) added on 2019-10-29 01:58:21: I finally realized that I could just download your ScidvsMac and see this for myself. This is what I learned. The original problem, and the core issue, is that Tk did not have a minimum width for a scrollbar. All mac scrollbars that I have seen are 15 pixels wide and an 8 pixel wide thumb with a 4 pixel gap on the left (vertical) or top (horizontal) side of the thumb and a 3 pixel gap on the right / bottom. In the ttk scrollbar I set the minimum width of the trough to 15 and the padding of the trough to {4, 4, 4, 3} / {4, 4, 3, 4}. When I ported the drawing code to the Tk scrollbar I did not realize that Tk might shrink the width of the scrollbar to make it less than the default width. But your help window had a scrollbar of width 12, forcing the width of the thumb to be 5. That caused the assertion error in the beginning, and that caused the thumb to not be drawn after I added a test to ensure that the thumb is at least 8 pixels wide. I have added a platform-specific minimum scrollbar width for the generic Tk scrollbar. The value is 15 on macOS and 0 on the others. That fixes the scrollbars in ScidvsMac. I know because I tested it. @fvogel: Does this look OK to you? @stevenaaus: Here is a tip: if you use ttk widgets whenever possible your app will look better. Also, you would not have run into this problem, although that would have been unfortunate since we would not have found this bug. stevenaaus added on 2019-10-28 23:56:04: Yes, your demo widget succeeds on my system, as do *some* of my text widgets. I tried to find which arg in the help window text widget may be the culprit, but without success. stevenaaus added on 2019-10-28 22:52:41: But i spoke too soon. Core dumps are gone, but the scrollbar isn't shown. See attached photo. The Engine has a vertical scrollbar, and the help widget (which has been the problematic one) should too, but it's missing. stevenaaus added on 2019-10-28 22:40:52: Actually, i think the speed problem is some event loop bottleneck somewhere. ScidvsMacs+wish8.6 limiting widget seems to be the progressbar, not the text widget. But since rendering issues seem to have been fixed, that's the important thing... stevenaaus added on 2019-10-28 22:21:55: That seems to fix it. :) BTW, not super important but there is some serious slow down in the text widget and/or framework on macOS. My 32bit carbon wish with Gregor's tk::text runs my crude inbuilt text benchmark in 4 to 4.2 seconds. The tested 64bit release version in at 15 to 29 seconds, depending on the number of open widgets. Both scidvspc CFLAGS -O3. I see the GNUMakefile is producing -Os optimized Frameworks.. which seems to be sourced from unix/configure. stevenaaus added on 2019-10-28 22:21:53: That seems to fix it. :) BTW, not super important but there is some serious slow down in the text widget and/or framework on macOS. My 32bit carbon wish with Gregor's tk::text runs my crude inbuilt text benchmark in 4 to 4.2 seconds. The tested 64bit release version in at 15 to 29 seconds, depending on the number of open widgets. Both scidvspc CFLAGS -O3. I see the GNUMakefile is producing -Os optimized Frameworks.. which seems to be sourced from unix/configure. marc_culler (claiming to be Marc Culler) added on 2019-10-28 12:41:45: I am still not able to reproduce this by removing or adding a scrollbar. Nonetheless, I am sure it will be fixed by adding a test to make sure that the thumb is at least 8 pixels wide and 8 pixels long before drawing it. And it is harmless to add the test. So I did that. @stevenaaus: Please test your app using checkin 22732cc0fd to branch bug-de579935a9. Thanks. stevenaaus added on 2019-10-28 08:30:16: rev tk-0c886a3d stevenaaus added on 2019-10-28 08:28:38: Ok... yes, the debug binary is there. Just not the whole debug framework anymore, cheers. And it is definitely the scrollbar or related, as our widget has an option to hide the scrollbar, and it only fails once scrollbar is displayed. Application Specific Information: Assertion failed: (corner_width >= 0 && 2 * corner_width <= CGRectGetWidth(rect)), function CGPathRef CGPathCreateWithRoundedRect(CGRect, CGFloat, CGFloat, const CGAffineTransform * _Nullable), file Paths/CGPath.cc, line 189. Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libsystem_kernel.dylib 0x00007fff95ebcf06 __pthread_kill + 10 1 libsystem_pthread.dylib 0x00007fff897804ec pthread_kill + 90 2 libsystem_c.dylib 0x00007fff8c91f6df abort + 129 3 libsystem_c.dylib 0x00007fff8c8e6dd8 __assert_rtn + 321 4 com.apple.CoreGraphics 0x00007fff973ff47b CGPathCreateWithRoundedRect + 1076 5 Tk 0x0000000105155b2f drawMacScrollbar + 1327 (tkMacOSXScrlbr.c:222) 6 Tk 0x000000010515509d TkpDisplayScrollbar + 1117 (tkMacOSXScrlbr.c:322) 7 Tcl 0x0000000104f72d36 TclServiceIdle + 77 8 Tcl 0x0000000104f55f17 Tcl_DoOneEvent + 350 9 Tk 0x000000010515bb79 -[TKContentView(TKWindowEvent) generateExposeEvents:] + 233 (tkMacOSXWindowEvent.c:1096) 10 Tk 0x000000010515b51a -[TKContentView(TKWindowEvent) drawRect:] + 458 (tkMacOSXWindowEvent.c:963) 11 com.apple.AppKit 0x00007fff907e5cd2 -[NSView _drawRect:clip:] + 3626 12 com.apple.AppKit 0x00007fff9083dcad -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 1873 13 com.apple.AppKit 0x00007fff907e33fb -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 838 14 com.apple.AppKit 0x00007fff907e4785 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5840 15 com.apple.AppKit 0x00007fff907e2be0 -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 334 16 com.apple.AppKit 0x00007fff907e0feb -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 2449 17 com.apple.AppKit 0x00007fff907dc3f5 -[NSView displayIfNeeded] + 1950 18 com.apple.AppKit 0x00007fff907dbc3c -[NSWindow displayIfNeeded] + 232 19 com.apple.AppKit 0x00007fff90e6041b ___NSWindowGetDisplayCycleObserver_block_invoke6365 + 476 20 com.apple.AppKit 0x00007fff907db5d6 __37+[NSDisplayCycle currentDisplayCycle]_block_invoke + 941 21 com.apple.QuartzCore 0x00007fff99fbae59 CA::Transaction::run_commit_handlers(CATransactionPhase) + 85 22 com.apple.QuartzCore 0x00007fff99fba314 CA::Context::commit_transaction(CA::Transaction*) + 160 23 com.apple.QuartzCore 0x00007fff99fb9fd4 CA::Transaction::commit() + 508 24 com.apple.QuartzCore 0x00007fff99fc5863 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 71 25 com.apple.CoreFoundation 0x00007fff953d8fc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 26 com.apple.CoreFoundation 0x00007fff953d8f37 __CFRunLoopDoObservers + 391 27 com.apple.CoreFoundation 0x00007fff953b7e48 CFRunLoopRunSpecific + 328 28 com.apple.HIToolbox 0x00007fff8e93f935 RunCurrentEventLoopInMode + 235 29 com.apple.HIToolbox 0x00007fff8e93f677 ReceiveNextEventCommon + 184 30 com.apple.HIToolbox 0x00007fff8e93f5af _BlockUntilNextEventMatchingListInModeWithFilter + 71 31 com.apple.AppKit 0x00007fff90683df6 _DPSNextEvent + 1067 32 com.apple.AppKit 0x00007fff90683226 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454 33 Tk 0x0000000105153da6 TkMacOSXEventsSetupProc + 198 (tkMacOSXNotify.c:306) 34 Tcl 0x0000000104f55ea6 Tcl_DoOneEvent + 237 35 Tk 0x00000001050191dd Tk_MainLoop + 45 (tkEvent.c:2078) 36 Tk 0x0000000105030feb Tk_MainEx + 2347 (tkMain.c:399) 37 tkscid 0x0000000104cfc45f main + 47 38 libdyld.dylib 0x00007fff96def5ad start + 1 marc_culler (claiming to be Marc Culler) added on 2019-10-27 22:52:14: I tried to reproduce this assertion error with the following script but was not able to see any problem. The script inserts 100000 lines of text. After running it the scrollbar thumb was correctly set to a small size which is large enough to allow the corners and to allow dragging the thumb with the mouse. There were no assertion errors.
set t [text .text -yscrollcommand [list .text.scroll set]]
set sb [ttk::scrollbar .text.scroll -command [list .text yview]]
pack $sb -side right -fill y
pack $t -expand yes -fill both
wm geometry . 640x400
for {set x 0} {$x < 100000} {incr x} {
.text insert end "$x asdf asdf asdf asdf asdf asdf asdf\n"
}
So I think I need to see a full crash report, with symbols.
fvogel added on 2019-10-27 22:04:43: Yes, it must be in the scollbar drawing code because the only place where CGPathCreateWithRoundedRect() is not yet protected by a CHECK_RADIUS is in drawMacScrollbar(). marc_culler added on 2019-10-27 21:57:06: We have seen this issue before, namely in [96bce57407], where the assertion failed because a button was being drawn before it was fully configured and consequently had size 1x1. Apple's drawing routine for rectangles with rounded corners requires, reasonably enough, that the sides of the rectangle be at least twice the radius of the arcs at the corners. In this case François says the assertion failure occurs when drawing a scrollbar. That seems very plausible. Both the track and the thumb are now drawn directly (in order to make scrollbars work correctly) and they are both rectangles with rounded corners. I will try to replicate this, but my initial guess is that this is happening because there are so many lines of text that the natural size of the thumb is too small to allow for the rounded corners. The only problem with that theory is that we tried to set a minimum thumb size which would prevent that from happening. But maybe the minimum size was not quite implemented correctly. fvogel added on 2019-10-27 08:06:13: And it's not in a text widget issue, it is either in the scrollbar code (tkMacOSXScrlbr.c) or in the theming code (ttkMacOSXTheme.c). fvogel added on 2019-10-27 08:04:01: This assertion is not in Tk but in a library used by Tk. It seems that some conditions on the parameters given to CGPathCreateWithRoundedRect are not satisfied, and the thing crashes! We will need to check these conditions before calling the function, to avoid such crash. There are only a few places calling CGPathCreateWithRoundedRect in the current codebase and they were all added recently (between [8140ebf0] fron Jan-19 and now). | |||
Attachments:
- Screen Shot 2019-10-29 at 8.48.04 AM.png [download] added by stevenaaus on 2019-10-28 22:52:18. [details]
