Wednesday, 15 May 2013

osx - Reloading NSOutlineView frequently causes crashes -



osx - Reloading NSOutlineView frequently causes crashes -

in application want search files in mac , if got files need reload nsoutlineview file. if reload items in nsoutlineview causes crash.

// calling method searching files.

[self performselectorinbackground:@selector(searchfiles) withobject:self];

// reloading outlineview

- (void)searchfiles { ------------------------- ------------------------- nsmutabledictionary *dictionary = [nsmutabledictionary dictionarywithobject:filelistarray forkey:@"children"]; [dictionary setobject:[nsstring stringwithformat:@"%ld",[filelist count]] forkey:@"parent"]; [listarray addobject:dictionary]; [outlineview reloaddata]; }

// delegates outlineview

- (bool)outlineview:(nsoutlineview *)outlineview isitemexpandable:(id)item { if ([item iskindofclass:[nsdictionary class]]) homecoming yes; else homecoming no; } - (nsinteger)outlineview:(nsoutlineview *)outlineview numberofchildrenofitem:(id)item { if (item == nil) homecoming [listarray count]; if ([item iskindofclass:[nsdictionary class]]) homecoming [[item objectforkey:@"children"] count]; homecoming 0; } - (id)outlineview:(nsoutlineview *)outlineview child:(nsinteger)index ofitem:(id)item { if (item == nil) homecoming [listarray objectatindex:index]; homecoming [[item objectforkey:@"children"] objectatindex:index]; homecoming nil; } - (id)outlineview:(nsoutlineview *)outlineview objectvaluefortablecolumn:(nstablecolumn *)thecolumn byitem:(id)item { if ([item iskindofclass:[nsdictionary class]]) homecoming [item objectforkey:@"parent"]; else homecoming item; homecoming nil; }

// crash log

2013-02-18 15:44:13.800 outlineviewreloaddemo[3054:303] *** assertion failure in -[nsoutlineview _expanditementry:expandchildren:startlevel:], /sourcecache/appkit/appkit-1187.34/tableview.subproj/nsoutlineview.m:1309 2013-02-18 15:44:13.802 outlineviewreloaddemo[3054:303] (null) should not expanded already! 2013-02-18 15:44:13.806 outlineviewreloaddemo[3054:303] ( 0 corefoundation 0x00007fff81eef0a6 __exceptionpreprocess + 198 1 libobjc.a.dylib 0x00007fff878a53f0 objc_exception_throw + 43 2 corefoundation 0x00007fff81eeeee8 +[nsexception raise:format:arguments:] + 104 3 foundation 0x00007fff8d4876a2 -[nsassertionhandler handlefailureinmethod:object:file:linenumber:description:] + 189 4 appkit 0x00007fff83fcb9b0 -[nsoutlineview _expanditementry:expandchildren:startlevel:] + 1153 5 appkit 0x00007fff83fb1c42 -[nsoutlineview _uncachednumberofrows] + 379 6 appkit 0x00007fff83feb938 -[nsoutlineview frameofcellatcolumn:row:] + 66 7 appkit 0x00007fff83feb44f -[nstableview drawrow:cliprect:] + 1636 8 appkit 0x00007fff83fdb4c3 -[nstableview drawrowindexes:cliprect:] + 397 9 appkit 0x00007fff83fdb321 -[nsoutlineview drawrowindexes:cliprect:] + 113 10 appkit 0x00007fff83fd9ea6 -[nstableview drawrect:] + 1269 11 appkit 0x00007fff83ebe144 -[nsview _drawrect:clip:] + 4217 12 appkit 0x00007fff83ebc7a1 -[nsview _recursivedisplayalldirtywithlockfocus:visrect:] + 1656 13 appkit 0x00007fff83ebcbb9 -[nsview _recursivedisplayalldirtywithlockfocus:visrect:] + 2704 14 appkit 0x00007fff83ebcbb9 -[nsview _recursivedisplayalldirtywithlockfocus:visrect:] + 2704 15 appkit 0x00007fff83eba7d2 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 817 16 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 17 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 18 appkit 0x00007fff83eba223 -[nsthemeframe _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 314 19 appkit 0x00007fff83eb5e4d -[nsview _displayrectignoringopacity:isvisiblerect:rectisvisiblerectforview:] + 4675 20 appkit 0x00007fff83e7fd73 -[nsview displayifneeded] + 1830 21 appkit 0x00007fff83e7f2ac _handlewindowneedsdisplayorlayoutorupdateconstraints + 738 22 foundation 0x00007fff8d4ee513 __nsfiretimer + 96 23 corefoundation 0x00007fff81eabda4 __cfrunloop_is_calling_out_to_a_timer_callback_function__ + 20 24 corefoundation 0x00007fff81eab8bd __cfrunloopdotimer + 557 25 corefoundation 0x00007fff81e91099 __cfrunlooprun + 1513 26 corefoundation 0x00007fff81e906b2 cfrunlooprunspecific + 290 27 hitoolbox 0x00007fff8b28b0a4 runcurrenteventloopinmode + 209 28 hitoolbox 0x00007fff8b28ae42 receivenexteventcommon + 356 29 hitoolbox 0x00007fff8b28acd3 blockuntilnexteventmatchinglistinmode + 62 30 appkit 0x00007fff83e7c613 _dpsnextevent + 685 31 appkit 0x00007fff83e7bed2 -[nsapplication nexteventmatchingmask:untildate:inmode:dequeue:] + 128 32 appkit 0x00007fff83e73283 -[nsapplication run] + 517 33 appkit 0x00007fff83e17cb6 nsapplicationmain + 869 34 outlineviewreloaddemo 0x0000000100001772 main + 34 35 libdyld.dylib 0x00007fff8206a7e1 start + 0 36 ??? 0x0000000000000003 0x0 + 3 )

my question how avoid crash ?

edit 1:

after adding [outline reloaddata]; in dispatch_async(dispatch_get_main_queue(), working without crash. if expand items leads crash. can't able figure out problem. crash log.

*** collection <__nsarraym: 0x106536f70> mutated while beingness enumerated. 0 corefoundation 0x00007fff81eef0a6 __exceptionpreprocess + 198 1 libobjc.a.dylib 0x00007fff878a53f0 objc_exception_throw + 43 2 corefoundation 0x00007fff81f82f98 __nsfastenumerationmutationhandler + 232 3 corefoundation 0x00007fff81ec7281 -[nsarray containsobject:] + 177 4 outlineviewdemo 0x000000010005ad60 -[mc_duplicatefinderviewcontroller outlineview:willdisplaycell:fortablecolumn:item:] + 800 5 appkit 0x00007fff83fed519 -[nstableview preparedcellatcolumn:row:] + 1573 6 appkit 0x00007fff83feccfc -[nsoutlineview preparedcellatcolumn:row:] + 56 7 appkit 0x00007fff83fecc07 -[nstableview _drawcontentsatrow:column:withcellframe:] + 47 8 appkit 0x00007fff83fecb7b -[nsoutlineview _drawcontentsatrow:column:withcellframe:] + 94 9 appkit 0x00007fff83feb63e -[nstableview drawrow:cliprect:] + 2131 10 appkit 0x00007fff83fdb4c3 -[nstableview drawrowindexes:cliprect:] + 397 11 appkit 0x00007fff83fdb321 -[nsoutlineview drawrowindexes:cliprect:] + 113 12 appkit 0x00007fff83fd9ea6 -[nstableview drawrect:] + 1269 13 appkit 0x00007fff83ebe144 -[nsview _drawrect:clip:] + 4217 14 appkit 0x00007fff83ebc7a1 -[nsview _recursivedisplayalldirtywithlockfocus:visrect:] + 1656 15 appkit 0x00007fff83ebcbb9 -[nsview _recursivedisplayalldirtywithlockfocus:visrect:] + 2704 16 appkit 0x00007fff83eba7d2 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 817 17 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 18 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 19 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 20 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 21 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 22 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 23 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 24 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 25 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 26 appkit 0x00007fff83ebbb24 -[nsview _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 5763 27 appkit 0x00007fff83eba223 -[nsthemeframe _recursivedisplayrectifneededignoringopacity:isvisiblerect:rectisvisiblerectforview:topview:] + 314 28 appkit 0x00007fff83eb5e4d -[nsview _displayrectignoringopacity:isvisiblerect:rectisvisiblerectforview:] + 4675 29 appkit 0x00007fff83e7fd73 -[nsview displayifneeded] + 1830 30 appkit 0x00007fff83e7f2ac _handlewindowneedsdisplayorlayoutorupdateconstraints + 738 31 appkit 0x00007fff8444a971 __83-[nswindow _postwindowneedsdisplayorlayoutorupdateconstraintsunlesspostingdisabled]_block_invoke_01208 + 46 32 corefoundation 0x00007fff81eb59b7 __cfrunloop_is_calling_out_to_an_observer_callback_function__ + 23 33 corefoundation 0x00007fff81eb5921 __cfrunloopdoobservers + 369 34 corefoundation 0x00007fff81e90d88 __cfrunlooprun + 728 35 corefoundation 0x00007fff81e906b2 cfrunlooprunspecific + 290 36 hitoolbox 0x00007fff8b28b0a4 runcurrenteventloopinmode + 209 37 hitoolbox 0x00007fff8b28ae42 receivenexteventcommon + 356 38 hitoolbox 0x00007fff8b28acd3 blockuntilnexteventmatchinglistinmode + 62 39 appkit 0x00007fff83e7c613 _dpsnextevent + 685 40 appkit 0x00007fff83e7bed2 -[nsapplication nexteventmatchingmask:untildate:inmode:dequeue:] + 128 41 appkit 0x00007fff83e73283 -[nsapplication run] + 517 42 appkit 0x00007fff83e17cb6 nsapplicationmain + 869 43 outlineviewdemo 0x0000000100001462 main + 34 44 libdyld.dylib 0x00007fff8206a7e1 start + 0 )

performselectorinbackground:withobject: runs selector on new background thread, while updates (and other operations) on ui must performed on main thread. hence crash, guess.

a simple way command update main thread utilize grand central dispatch (gcd), this:

dispatch_async(dispatch_get_main_queue(), ^{ [outlineview reloaddata]; });

osx cocoa nsoutlineview

No comments:

Post a Comment