Mac OS X 程序提供 EXEC_BAD_ACCESS

发布于 2024-11-07 03:56:00 字数 1993 浏览 0 评论 0原文

在我的模块之一中,我需要维护基于事件的机制。逻辑是:

发送事件:

-(void)addEvent:(EventData *)pData{

    [self enQueueEvent:pData];

    [[NSNotificationCenter defaultCenter]
     postNotificationName:EVENT_NAME
     object:nil ];

}

-(void)enQueueEvent:(EventData *)pData{
    [pEventLock lock];
    [self.pEventArray insertObject:(NSObject *)pData atIndex:0];
    [pEventLock unlock];
}

收到事件时:

-(void)EventHandler: (NSNotification *) notification
{
    [self log:@"event Handled"];
    EventData *pData = [self deQueueEvent];

    if(pData){
        switch(pData->eModuleId){
            case UI_EVENT:{
                [UIController HandleUICallBack:(EventType)pData->eType LParam:pData->lParam WParam:pData->wParam];
            }
        }
        pData->lParam = 0x00;
        pData->wParam = 0x00;
        free(pData);
    //  [pData release];
        //[self removeProcessedEvent];  
    }
}

-(EventData *)deQueueEvent{
    [pEventLock lock];
    NSObject *pData = [self.pEventArray lastObject];
    [self.pEventArray removeLastObject];
    [pEventLock unlock];
    return (EventData *)pData;
}


>>>>>>> Adding Header File Declaration >>>>>>>>>>>>>>>>>>>
typedef struct __eventData{
    ModuleId eModuleId;
    EventType eType;
    void *lParam;
    void *wParam;

}EventData;

@interface CommEventHandler : NSObject {
    NSMutableArray *pEventArray;
    bool shouldStartTimer;
    int timerValue;
    NSLock  *pEventLock;
}

@property(nonatomic,retain)NSMutableArray *pEventArray;
@property(nonatomic,retain)NSLock  *pEventLock;

<<<<<<<<<<<<<<<< End of Header File <<<<<<<<<<<<

我相信这很容易理解。现在发生的事情是,当我在 10.6 | 中运行程序时应用程序名称 |调试| i386 它运行得很好,但是当我在 10.6 | 中运行该程序时应用程序名称 |调试| X86_64 将节点插入事件数组时出错。谁能告诉我如何调试?我检查了所有内存方面,但没有找到任何东西。

In one of my modules I need to maintain event-based mechanism. The logic is:

To send the event:

-(void)addEvent:(EventData *)pData{

    [self enQueueEvent:pData];

    [[NSNotificationCenter defaultCenter]
     postNotificationName:EVENT_NAME
     object:nil ];

}

-(void)enQueueEvent:(EventData *)pData{
    [pEventLock lock];
    [self.pEventArray insertObject:(NSObject *)pData atIndex:0];
    [pEventLock unlock];
}

When event received:

-(void)EventHandler: (NSNotification *) notification
{
    [self log:@"event Handled"];
    EventData *pData = [self deQueueEvent];

    if(pData){
        switch(pData->eModuleId){
            case UI_EVENT:{
                [UIController HandleUICallBack:(EventType)pData->eType LParam:pData->lParam WParam:pData->wParam];
            }
        }
        pData->lParam = 0x00;
        pData->wParam = 0x00;
        free(pData);
    //  [pData release];
        //[self removeProcessedEvent];  
    }
}

-(EventData *)deQueueEvent{
    [pEventLock lock];
    NSObject *pData = [self.pEventArray lastObject];
    [self.pEventArray removeLastObject];
    [pEventLock unlock];
    return (EventData *)pData;
}


>>>>>>> Adding Header File Declaration >>>>>>>>>>>>>>>>>>>
typedef struct __eventData{
    ModuleId eModuleId;
    EventType eType;
    void *lParam;
    void *wParam;

}EventData;

@interface CommEventHandler : NSObject {
    NSMutableArray *pEventArray;
    bool shouldStartTimer;
    int timerValue;
    NSLock  *pEventLock;
}

@property(nonatomic,retain)NSMutableArray *pEventArray;
@property(nonatomic,retain)NSLock  *pEventLock;

<<<<<<<<<<<<<<<< End of Header File <<<<<<<<<<<<

I believe this is easy to understand. Now what is happening is that when I run the program in 10.6 | App Name | Debug | i386 it runs perfectly fine, but when I run the program in 10.6 | App Name | Debug | X86_64 it faults while inserting a node into the Event array. Can anyone give me a clue how to debug ? I checked all memory aspects, but failed to find anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖不如嘢 2024-11-14 03:56:00

如果 CommEventDataEventData 相同,则两者都不是 Objective-C 类。因此,您不能将 CommEventData * 类型的值添加到 NSMutableArray 中,因为 NSMutableArray 需要一个 Objective-C 对象 — 特别是一个 Objective-响应 -retain-release 的 C 对象。如果添加的不是对象,无论 (NSObject *) 类型转换如何,这都会崩溃。

如果将 EventDataCommEventData 转换为 Objective-C 类,则可以使用 NSMutableArray

否则,如果您想要存储指向非 Objective-C 对象的值的指针(例如指向结构的指针),请考虑使用NSPointerArray。请注意,由于 NSPointerArray 允许任意(指向)值,因此它不会获取或释放其元素的所有权。

If CommEventData is the same as EventData, then both aren’t Objective-C classes. As such, you cannot add values of type CommEventData * to an NSMutableArray because NSMutableArray expects an Objective-C object — in particular, an Objective-C object that responds to both -retain and -release. This will crash if what’s being added is not an object regardless of the (NSObject *) typecast.

If you convert EventData and CommEventData to Objective-C classes, you can use NSMutableArray.

Otherwise, if you want to store pointers to values that are not Objective-C objects (e.g. pointers to structs), consider using NSPointerArray instead. Note that since NSPointerArray allows arbitrary (pointers to) values, it doesn’t take ownership of nor release its elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文