0

我已经浏览了 EXC_BAD_ACCESS 上的所有相关帖子,但还没有弄清楚这个概念。也许我应该首先学习基本概念,但现在我需要解决这个问题..所以,介入以获得一些专家帮助..

这是我的代码(我只粘贴了相关部分)

//In .h
//=====
        @interface GUIMainController : GUIController {
        ::
        ::
            NSArray* shufflePositionArray;
        }

        @property (retain)NSArray* shufflePositionArray;

//In .mm
//=======
        @synthesize shufflePositionArray;

        -(void)start
        {
        ::
            NSString* shufflePositionArrayPlistPath=nil;
            NSString* shufflePositionArrayPlistPathFromConfiguration=
            @"/MyApp/Configuration/ShufflePositionArray.plist";
           if ([[NSFileMngrdfltMngr]fileExistsAtPath:shufflePositionArrayPlistPathFromConfig])
            {
             self.shufflePositionArray=  
                     [NSArrayarrayWithContentsOfFile:shufflePositionArrayPlistPathFromConfig];
            }
            if (self.shufflePositionArray==nil)  {
           shufflePositionArrayPlistPath=
           [thisBundle pathForResource:@"ShufflePositionArray" ofType:@"plist"];

             if (shufflePositionArrayPlistPath!=nil) {
                    self.shufflePositionArray=
                          [NSArray arrayWithContentsOfFile:shufflePositionArrayPlistPath];
                }
            }
        }

//From another method:
//====================

        -(void)shuffleWindow
        {
        ::
            if (shufflePositionArray!=nil && [self.shufflePositionArray count]!=0){
        :: // some code
            if (shufflePositionArray!=nil && [self.shufflePositionArray count]!=0){
        ::
        ::  // some code
            processwindowlocation_=(processwindowlocation_+1)%[self.shufflePositionArray count];    
                 // ######## there is a crash here !!!!!!   #############
            }
         }

        }
//And then..we release it here:
//==============================
        -(void)dealloc {

            if(shufflePositionArray!=nil){
                [shufflePositionArray release];
            }
            [super dealloc];
        }

我对 obj-C 完全陌生,任何形式的帮助都将不胜感激。提前致谢。

这是崩溃:

崩溃的线程:0 调度队列:com.apple.main-thread

异常类型:EXC_BAD_ACCESS (SIGSEGV) 异常代码:0x0000000000000018 处的 KERN_INVALID_ADDRESS

0x18 附近的 VM 区域:--> __TEXT 000000010d89a000-000000010d927000 [564K] rx/rwx SM=COW /Ihome/MyAppCE.app/Contents/MacOS/MyAppCE

应用程序特定信息:objc_msgSend() 选择器名称:count

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                 0x00007fff82c5d62f objc_msgSend_vtable9 + 47
1   com.apple.AppKit                0x00007fff88842b05 +[NSScreen screens] + 847
2   com.apple.AppKit                0x00007fff88844575 +[NSScreen _zeroScreenHeight] + 44
3   com.apple.AppKit                0x00007fff888b15cf _NSShapeRoundedWindowWithWeighting + 61
4   com.apple.AppKit                0x00007fff888507c3 -[NSThemeFrame shapeWindow] + 336
5   com.apple.AppKit                0x00007fff888b055c -[NSThemeFrame setFrameSize:] + 457
6   com.apple.AppKit                0x00007fff888af68f -[NSWindow _setFrame:updateBorderViewSize:] + 929
7   com.apple.AppKit                0x00007fff888aee04 -[NSWindow _oldPlaceWindow:] + 1142
8   com.apple.AppKit                0x00007fff888ae2b9 -[NSWindow _setFrameCommon:display:stashSize:] + 1837
9   com.Apple.Phoenix.UI            0x0000000110580045 -[GUIMainController shuffleWindow] + 1477 (GUIMainController.mm:470)
10  com.Apple.Phoenix.UI            0x0000000110586aef -[GUIPeriodicController periodic:] + 2399 (GUIPeriodicController.mm:219)
11  com.apple.Foundation            0x00007fff86867463 __NSFireTimer + 96
12  com.apple.CoreFoundation        0x00007fff81df5804 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
13  com.apple.CoreFoundation        0x00007fff81df531d __CFRunLoopDoTimer + 557
14  com.apple.CoreFoundation        0x00007fff81ddaad9 __CFRunLoopRun + 1529
15  com.apple.CoreFoundation        0x00007fff81dda0e2 CFRunLoopRunSpecific + 290
16  com.apple.HIToolbox             0x00007fff83dc6eb4 RunCurrentEventLoopInMode + 209
17  com.apple.HIToolbox             0x00007fff83dc6b94 ReceiveNextEventCommon + 166
18  com.apple.HIToolbox             0x00007fff83dc6ae3 BlockUntilNextEventMatchingListInMode + 62
19  com.apple.AppKit                0x00007fff8887f533 _DPSNextEvent + 685
20  com.apple.AppKit                0x00007fff8887edf2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
21  com.Apple.Phoenix.UI            0x0000000110594b52 processUIEvent() + 290 (PhoenixCECocoaGUI.mm:363)
22  com.Apple.Phoenix.UI            0x000000011058e152 Phoenix::Core::UICocoaImpl::processEvent() + 44 (UICocoaImpl.mm:61)
23  com.Apple.MyAppCE               0x000000010d8ae62e main + 2302 (mainer.cpp:180)
24  com.Apple.MyAppCE               0x000000010d89b604 start + 52


Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x000000000000000f  rbx: 0xffffffffffffffff  rcx: 0x0000000001010101  rdx: 0x0000000000000001
  rdi: 0xffffffffffffffff  rsi: 0x00007fff7268ea80  rbp: 0x00007fff523631b0  rsp: 0x00007fff52363028
   r8: 0x00007fff72435a30   r9: 0x00007fff72435a01  r10: 0x0000000000000000  r11: 0x00007f968c000600
  r12: 0x0000000000000000  r13: 0x0000000000000000  r14: 0x0000000000000001  r15: 0x000000000000000c
  rip: 0x00007fff82c5d62f  rfl: 0x0000000000010206  cr2: 0x0000000000000018
4

1 回答 1

1

如果发生崩溃,请发布回溯。

假设您没有删除一些相关代码,唯一processwindowlocation_=(processwindowlocation_+1)%[self.shufflePositionArray count];可能崩溃的方法(假设这实际上是崩溃的行)是self无效或shufflePositionArray无效。

请注意,无效并不意味着nilnil只会返回0计数。

还要注意,这里检查非零是没有意义的:

        if(shufflePositionArray!=nil){
            [shufflePositionArray release];
        }

那次崩溃很奇怪。考虑到您的代码,我真的不会期望那里发生崩溃。

尝试打开僵尸检测(仪器——如果您需要,Google 可以找到更多信息)并查看它是否是过度发布问题。

于 2013-06-04T03:24:22.110 回答