[Openmcl-devel] One-time problem

Paul Krueger plkrueger at comcast.net
Wed Apr 3 06:15:08 PDT 2013


Yeah, I have already been adding main-thread execution in lots of places. I have been doing quite a bit of work with the new (as of OSX 10.7) constraint facility and have discovered that if an instance uses constraints internally (as a few now do), then just creating it will cause those constraints to be immediately evaluated. And I have seen problems if that isn't done on the main thread (especially if the constraints are added using an #/updateConstraints method). Because I'm now using constraints for several custom subclasses I pretty much assure that all those are created on the main thread. This problem was with old code that I haven't yet modified to do that. I'm not sure why I didn't think of that myself since I'm doing it so much already.

You can't generally know whether an object uses constraints internally or not unless you explicitly look at all subviews. I have some code that analyzes constraints which walks through all subviews. I just checked and it appears that ns-open-panels do NOT use constraints in any of its subviews (at least as of OSX 10.8.2). But I think generally speaking it will become imperative to create new instances of many view objects in the main thread as Apple changes those objects to use constraints. That may be something you'll want to enforce when making view instances.

Thinking about it, ns-open-panels are a subclass of window and windows are generally tracked by the application, so maybe that's causing problems. Anyway, I'll make the change you suggest just to be safe and hopefully that will take care of the problem. Since it has happened exactly once in over three years of using this code we may never know for sure.

On Apr 3, 2013, at 6:40 AM, Gary Byers <gb at clozure.com> wrote:

> I don't know, but I think that it's generally wise to develop an almost
> superstitious fear of doing any GUI things in any thread but the event
> thread (and creating an NSOpenPanel - even if you don't display it - may
> count as "doing a GUI thing.")
> 
> If this only happens very infrequently, it may be hard to know whether
> that's indeed the problem, but if you change your code and it ever happens
> again, we'd at least know what the problem isn't.
> 
> On Tue, 2 Apr 2013, Paul Krueger wrote:
> 
>> I ran into a one-time problem that I don't quite know what to make of. When loading some code that I have used without problems for some time I got an Objective-C runtime exception. The relevant issue starts at level 6 in the backtrace shown below. The Lisp form that was being executed at that point was a pretty generic:
>> 	(make-instance ns:ns-open-panel)
>> 
>> After popping out of the error I was able to type that same form into the listener without problem. I got out and back into lisp and loaded everything without incident. The problem is apparently not reproducible. I'm sending this in the off chance that the backtrace will be useful to somebody else.
>> 
>> Welcome to Clozure Common Lisp Version 1.9-dev-r15567M-trunk  (DarwinX8664)!
>> ? (require :loan-doc)
>>> Error: Objective-C runtime exception:
>>>       *** -[__NSArrayM removeObjectAtIndex:]: index 16 beyond bounds [0 .. 15]
>>> While executing: #<Anonymous Function #x300000F9EEEF>, in process Listener(4).
>>> Type cmd-. to abort, cmd-\ for a list of available restarts.
>>> Type :? for other options.
>> 1 > :b
>> (25DD71A8) : 0 (FUNCALL #'#<Anonymous Function #x300000F9EEEF> #<NS-OPEN-PANEL <NSOpenPanel: 0x23700a30> (#x23700A30)> #S(CCL::OBJC-SELECTOR :NAME "initWithContentRect:styleMask:backing:defer:" :%SEL #<A Foreign Pointer #x7FFF949EB44F>) #<NS-RECT 500 X 200 @ 200,200 [gcable] (#x1F1A30) #x30200158601D> 15 2 T) 597
>> (25DD71E8) : 1 (FUNCALL #'#<(:OBJC-DISPATCH NEXTSTEP-FUNCTIONS:|initWithContentRect:styleMask:backing:defer:|)> ???) 541
>> (25DD7220) : 2 (SEND-INIT-MESSAGE-FOR-CLASS #<OBJC:OBJC-CLASS NS:NS-OPEN-PANEL (#x7FFF7B298EA8)> (:DEFER T :BACKING 2 :STYLE-MASK ...)) 1261
>> (25DD7278) : 3 (%%CNM-WITH-ARGS-COMBINED-METHOD-DCODE #(#<STANDARD-GENERIC-FUNCTION ALLOCATE-INSTANCE #x30200002DB8F> (#<#> #<#>) (#<STANDARD-GENERIC-FUNCTION ALLOCATE-INSTANCE #x30200002DB8F> #) #<Compiled-function CCL::%%CNM-WITH-ARGS-CHECK-INITARGS #x3000001F6B3F> (#<#> #<#>)) (#<OBJC:OBJC-CLASS NS:NS-OPEN-PANEL (#x7FFF7B298EA8)> :DEFER T :BACKING 2 ...) (#(#<STANDARD-GENERIC-FUNCTION ALLOCATE-INSTANCE #x30200002DB8F> # # # #) (#<#>) . 79408752)) 917
>> (25DD72D0) : 4 (%CALL-NEXT-METHOD-WITH-ARGS (#(#<STANDARD-GENERIC-FUNCTION ALLOCATE-INSTANCE #x30200002DB8F> # # # #) (#<#>) . 79408752) #<OBJC:OBJC-CLASS NS:NS-OPEN-PANEL (#x7FFF7B298EA8)> :DEFER T :BACKING 2 :STYLE-MASK 15 :WITH-CONTENT-RECT #<NS-RECT 500 X 200 @ 200,200 [gcable] (#x1F1A30) #x30200158601D>) 365
>> (25DD7318) : 5 (%%CNM-WITH-ARGS-COMBINED-METHOD-DCODE #(#<STANDARD-GENERIC-FUNCTION ALLOCATE-INSTANCE #x30200002DB8F> (#<#> #<#>) (#<STANDARD-GENERIC-FUNCTION ALLOCATE-INSTANCE #x30200002DB8F> #) #<Compiled-function CCL::%%CNM-WITH-ARGS-CHECK-INITARGS #x3000001F6B3F> (#<#> #<#>)) 79408752 NIL) 1029
>> (25DD7390) : 6 (FUNCALL #'#<#<STANDARD-METHOD MAKE-INSTANCE (OBJC:OBJC-CLASS-OBJECT)>> #<OBJC:OBJC-CLASS NS:NS-OPEN-PANEL (#x7FFF7B298EA8)>) 165
>> (25DD73C0) : 7 (FUNCALL #'#<(INTERFACE-UTILITIES::INITIALIZE-DOC-CONTROLLER (LISP-DOC-CONTROLLER))> #<LISP-DOC-CONTROLLER <LispDocController: 0x1f5e70> (#x1F5E70)> :DOC-CLASS #<OBJC:OBJC-CLASS LOAN-DOC (#x20ECEA00)> :DELEGATE-CLASS NIL :DOC-TYPE "Loan" :FILE-EXT "loan" :APP-BUNDLE NIL) 509
>> (25DD7458) : 8 (%%CHECK-KEYWORDS #(1 #(:APP-BUNDLE :FILE-EXT :DOC-TYPE :DELEGATE-CLASS :DOC-CLASS) #<COMPILED-LEXICAL-CLOSURE #<#> #x30200136FBDF>) 79408790) 221
>> (25DD7510) : 9 (MAKE-DOC-CONTROLLER #<OBJC:OBJC-CLASS LOAN-DOC (#x20ECEA00)> NIL "Loan" "loan" NIL) 533
>> (25DD7578) : 10 (CALL-CHECK-REGS MAKE-DOC-CONTROLLER #<OBJC:OBJC-CLASS LOAN-DOC (#x20ECEA00)> NIL "Loan" "loan") 221
>> (25DD75B0) : 11 (CHEAP-EVAL-IN-ENVIRONMENT (SET '*LOAN-DOC-CONTROLLER* (MAKE-DOC-CONTROLLER # NIL "Loan" "loan")) #<CCL::LEXICAL-ENVIRONMENT #x3020015877ED>) 3453
>> (25DD7600) : 12 (FUNCALL #'#<(:INTERNAL CCL::PROGN-IN-ENV CCL::CHEAP-EVAL-IN-ENVIRONMENT)> ((EVAL-WHEN # #) (CCL::%DEFVAR-INIT *LOAN-DOC-CONTROLLER* # NIL) '*LOAN-DOC-CONTROLLER*) #<CCL::LEXICAL-ENVIRONMENT #x302000E945DD> #<CCL::LEXICAL-ENVIRONMENT #x30200156E71D>) 285
>> (25DD7650) : 13 (FUNCALL #'#<(:INTERNAL CCL::WITH-COMPILATION-UNIT-BODY CCL::LOAD-FROM-STREAM)>) 757
>> (25DD76D8) : 14 (CALL-WITH-COMPILATION-UNIT #<COMPILED-LEXICAL-CLOSURE (:INTERNAL CCL::WITH-COMPILATION-UNIT-BODY CCL::LOAD-FROM-STREAM) #x25EF9E5F> :OVERRIDE NIL) 197
>> (25DD7720) : 15 (LOAD-FROM-STREAM #<BASIC-FILE-CHARACTER-INPUT-STREAM ("/Applications/ccl/contrib/cocoa-ide/krueger/InterfaceProjects/Loan Document/loan-doc.lisp"/9 UTF-8) #x302000E956CD> NIL) 357
>> (25DD7760) : 16 (%LOAD #P"/Applications/ccl/contrib/cocoa-ide/krueger/InterfaceProjects/Loan Document/loan-doc.lisp" NIL NIL :ERROR :DEFAULT NIL) 5181
>> (25DD78B8) : 17 (LOAD #P"/Applications/ccl/contrib/cocoa-ide/krueger/InterfaceProjects/Loan Document/loan-doc" :VERBOSE NIL :PRINT NIL :IF-DOES-NOT-EXIST :ERROR :EXTERNAL-FORMAT :DEFAULT :PRESERVE-OPTIMIZATION-SETTINGS NIL) 1021
>> (25DD7960) : 18 (MODULE-PROVIDE-SEARCH-PATH :LOAN-DOC) 197
>> (25DD7998) : 19 (SOME-XX-ONE 0 NIL #<COMPILED-LEXICAL-CLOSURE (:INTERNAL REQUIRE) #x302000E8F62F> (ASDF::MODULE-PROVIDE-ASDF CCL::MODULE-PROVIDE-SEARCH-PATH)) 581
>> (25DD79F0) : 20 (REQUIRE :LOAN-DOC NIL) 773
>> (25DD7A50) : 21 (CALL-CHECK-REGS REQUIRE :LOAN-DOC) 221
>> (25DD7A88) : 22 (TOPLEVEL-EVAL (REQUIRE :LOAN-DOC) NIL) 693
>> (25DD7B20) : 23 (READ-LOOP :INPUT-STREAM #<SYNONYM-STREAM to *TERMINAL-IO* #x302000E1ACBD> :OUTPUT-STREAM #<SYNONYM-STREAM to *TERMINAL-IO* #x302000E1AB5D> :BREAK-LEVEL 0 :PROMPT-FUNCTION #<Compiled-function (:INTERNAL CCL::READ-LOOP) (Non-Global)  #x30000050FF9F>) 2269
>> (25DD7D78) : 24 (RUN-READ-LOOP :BREAK-LEVEL 0) 157
>> (25DD7DA0) : 25 (TOPLEVEL-LOOP) 101
>> (25DD7DC8) : 26 (FUNCALL #'#<(:INTERNAL CCL::MAKE-MCL-LISTENER-PROCESS)>) 645
>> (25DD7E60) : 27 (RUN-PROCESS-INITIAL-FORM #<COCOA-LISTENER-PROCESS Listener(4) [Active] #x302000E83F5D> (#<COMPILED-LEXICAL-CLOSURE # #x302000E83A1F>)) 669
>> (25DD7EF0) : 28 (FUNCALL #'#<(:INTERNAL (CCL::%PROCESS-PRESET-INTERNAL (PROCESS)))> #<COCOA-LISTENER-PROCESS Listener(4) [Active] #x302000E83F5D> (#<COMPILED-LEXICAL-CLOSURE # #x302000E83A1F>)) 573
>> (25DD7F98) : 29 (FUNCALL #'#<(:INTERNAL CCL::THREAD-MAKE-STARTUP-FUNCTION)>) 277
>> _______________________________________________
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
>> http://clozure.com/mailman/listinfo/openmcl-devel
>> 
>> 




More information about the Openmcl-devel mailing list