添加到 NSOperationQueue 时 exc_bad_access
我已经对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有在构造函数中调用
[super init]
吗?假设您正在子类化 NSOperation (或 NSObject 等...),您可能应该这样做!
You're not calling
[super init]
inside your constructor?Assuming you're subclassing NSOperation (or NSObject etc...), you probably should!