添加到 NSOperationQueue 时 exc_bad_access

发布于 2024-11-26 05:02:29 字数 1236 浏览 2 评论 0原文

我已经对 NSOperation 进行了子类化,并且 - (void) main 没问题,(因为它在使用 NSOperation 之前就可以工作),我还单步执行了 init 方法,并且变量已正确初始化。 在 -(id) initWithSampleBuffer: 完成后一切都很艰难,我试图将 uploadOperation 添加到 NSOperationQueue:

UploadOperation *ulOp = [[UploadOperation alloc] initWithSampleBuffer:sampleBuffer];
[queue addOperation:ulOp]; //here i get exc_bad_access
[ulOp release];

我得到 exc_bad_access。我尝试过断点,可以看到队列存在,ulOp 也是如此。 我无法弄清楚我做错了什么,因为据我了解,当您尝试将“消息”传递给已释放的内容时,就会发生 exc_bad_access ,显然,它们都不是。

- (id)initWithSampleBuffer:(CMSampleBufferRef) aSampleBuffer {
    sampleBuffer = aSampleBuffer;

    VideoStreamViewController *vc = [VideoStreamViewController shared];
    ul = [[Uploader alloc] initWithURL:[NSURL alloc] filePath:@"" delegate:vc doneSelector:@selector(didFinishUpload:) errorSelector:@selector(uploadFailed:)];

    return self;
}

然而,上传器的东西不是问题(我已经删除了它,但仍然得到相同的结果)。据我所知,CMSampleBuffer 对象没有问题,它已初始化!

队列初始化:

在 .h 中:

NSOperationQueue *queue;
@property (nonatomic, retain) NSOperationQueue *queue;

在 .m 中:

@synthesize queue;
self.queue = [[NSOperationQueue alloc] init];
[queue setMaxConcurrentOperationCount:1];

I've subclassed NSOperation and - (void) main is ok, (since it worked before using NSOperation), I've also stepped through the init method and the variables are initialized correctly.
All tough after the -(id) initWithSampleBuffer: is done and I'm trying to add the uploadOperation to the NSOperationQueue:

UploadOperation *ulOp = [[UploadOperation alloc] initWithSampleBuffer:sampleBuffer];
[queue addOperation:ulOp]; //here i get exc_bad_access
[ulOp release];

I get exc_bad_access. I've tried breakpoints and I can see that queue exists and so do ulOp.
I can't figure out what I'm doing wrong, since to my understanding exc_bad_access occurs when you're trying to pass a "message" to something that is already deallocated, and clearly, none of them are.

- (id)initWithSampleBuffer:(CMSampleBufferRef) aSampleBuffer {
    sampleBuffer = aSampleBuffer;

    VideoStreamViewController *vc = [VideoStreamViewController shared];
    ul = [[Uploader alloc] initWithURL:[NSURL alloc] filePath:@"" delegate:vc doneSelector:@selector(didFinishUpload:) errorSelector:@selector(uploadFailed:)];

    return self;
}

however the Uploader stuff, isn't the problem (i've removed it and still get the same result). and from what i can se there no problem with the CMSampleBuffer object, it is initialized!

init of queue:

in .h:

NSOperationQueue *queue;
@property (nonatomic, retain) NSOperationQueue *queue;

in .m:

@synthesize queue;
self.queue = [[NSOperationQueue alloc] init];
[queue setMaxConcurrentOperationCount:1];

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

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

发布评论

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

评论(1

流绪微梦 2024-12-03 05:02:29

您没有在构造函数中调用 [super init] 吗?

假设您正在子类化 NSOperation (或 NSObject 等...),您可能应该这样做!

You're not calling [super init] inside your constructor?

Assuming you're subclassing NSOperation (or NSObject etc...), you probably should!

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