-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
appendPixelBuffer EXC_BAD_ACCESS #4
Comments
i getting the same error,any solution now? |
Hi folks, Al |
In the // append pixelBuffer on a async dispatch_queue, the next frame is rendered whilst this one appends
// must not overwhelm the queue with pixelBuffers, therefore:
// check if _append_pixelBuffer_queue is ready
// if it’s not ready, release pixelBuffer and bitmapContext
if (dispatch_semaphore_wait(_pixelAppendSemaphore, DISPATCH_TIME_NOW) == 0) {
dispatch_async(_append_pixelBuffer_queue, ^{
BOOL success = [_avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:time];
if (!success) {
NSLog(@"Warning: Unable to write buffer to video");
}
CGContextRelease(bitmapContext);
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
CVPixelBufferRelease(pixelBuffer);
dispatch_semaphore_signal(_pixelAppendSemaphore);
});
} else {
CGContextRelease(bitmapContext);
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
CVPixelBufferRelease(pixelBuffer);
} Could you try replacing it with the following to see if it solves the issue? BOOL success = [_avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:time];
if (!success) {
NSLog(@"Warning: Unable to write buffer to video");
}
CGContextRelease(bitmapContext);
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
CVPixelBufferRelease(pixelBuffer); Current implementation uses a separate queue to append pixel buffers which increases the video frame rate. However, this is quite possibly the cause of the issue. Let me know if this prevents the crash - if so, it will unfortunately also lead to a drop in frame rate. I'll see if there's anything I can do to solve this. Al |
It occur with my own app.Sometimes it work perfect.It crash both immediately and record for a while. |
By the way,will you adding sounds? |
Hi @tobira, |
Thanks for your suggestions,that is helpful! |
Hi @tobira @alskipp ...Could you find out this issue ? I think this is some memory issue. If i finish recording screen and again hit the record button the app crashes always at the same place - BOOL success = [_avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:time]; |
It's kind of promising that it crashes consistently with the same action! The problem I have is that I've been unable to reproduce the crash. I've tested on an iPhone 5s and 4S and I've not managed to cause the EXC_BAD_ACCESS. Needless to say, this makes it very difficult to track down the bug. @nihtin9mk I suspect that if the crash occurs every time you start a second recording that this is related to creating the first frame of your live video capture. I'll continue this discussion on issue #5. |
HI @alskipp - please try to record a screen and after finishes quit the app and again start recording, suddenly it crashes at times. An the issue is not related to second video capture, I have described in issue #5. |
Hi @nihtin9mk, |
So kind of you. Thank you @alskipp. I am also trying to find out the issue. |
Just tried the record, quit, record routine several times with my own app - I've not yet been able to reproduce the crash 😕 |
Hi, sorry for being out, |
I just updated xcode and ipad to ios8 and the EXC_BAD_ACCESS error disappeared. Everything works now like a charm! |
I'd like to say I fixed the bug by force of will alone, but that might not be entirely accurate. I'll have more to say on the matter when I return home. With any luck the mystery bug fix continues to work for you. |
Hi @alskipp - waiting for your solution. |
Hi |
Hi @PerMartin, thanks for investigating the issue - that sounds very promising. Why didn't I think of running the static analyser? I've been spending my time trying to get the thing to crash in my app (and failing) - multi-threaded memory bugs are a nightmare! I'll alter the way createPixelBufferAndBitmapContext is called and see if that fixes the crash for everyone. If it does (and you happen to live in London), then I owe you a pint of finest ale! Unfortunately I won't have time to make the changes tonight - hopefully tomorrow. All the best, |
Hi @alskipp..I know you are so busy, but could you figure out the issue. I am trying to fix it. |
Hi @alskipp .. Waiting for your response. |
Apologies for the delay, but things have been a bit hectic lately. I've added an experimental branch to the repository: Could you check this out and see if it works for you? All I've done is create the CGContext in the Al |
Thank you @alskipp , for the help - |
I have also tried the experimental branch and have the same crash: |
I have the same issue, it happens at the same point from time to time. Trying to debug, no luck yet. Any guidance will be appreciated. Another issue on iPhone 5c when you switch/minimize application when recording the video, recording stops when you come back to the app, [_avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:time] returns NO. |
@alskipp This is occurring for me mostly on an iPhone 6 device running iOS 8. The crash occurs almost every time. On an iPhone 5 running iOS 8 it only crashes every now and then, but always on the line mentioned above. I am doing a lot of [UIView animations] and my thoughts were that the use of semaphores was somehow trying to access a pixelBuffer that is somehow already released from the view context (just a random theory...). Trying my best to debug. Here is a Crashlytics report, hopefully somewhat helpful but my guess is no: 4 |
I also got this from a Sentry report (XCode always breaks on the same line but never seems to throw the exception in the console) NSInvalidArgumentException: ** -[AVAssetWriterInputPixelBufferAdaptor appendPixelBuffer:withPresentationTime:] invalid parameter not satisfying: pixelBuffer != ((void)0) This is one of those things that I don't know enough about to say "ah its because x,y, or z is causing the bug". I have used several other libraries that do this sort of thing. One is Glimpse (which basically creates an array of UIImages, then at the end of the recording, processes them). It doesn't use a CVPixelBufferPool but rather draws a CGImage into the CVPixelBuffer and appends that into a video frame. One thing that I tried was to assign pixel buffer attributes (the same ones that are assigned to your CVPixelBufferPool actually) and this seemed to cause a lot less crashing on my devices. However, I eventually got the crash shown at the top of this comment...any thoughts on whether the issue lies in the attributes not being set for the pixel buffer adapter? i.e. your line: _avAdaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:_videoWriterInput sourcePixelBufferAttributes:nil]; Sorry if that sounds completely stupid, but I'm just trying to compare the differences between Glimpse https://github.com/wess/Glimpse (which works flawlessly on iphone 4, 5, 5s, 6, and 6+, both ios 7 and 8) and yours (which seems to crash more frequently on some devices, particularly iphone 6). I would prefer your library because it is wayyy more efficient and processes the output file extremely quickly. I'll keep digging and let you know if I have any revelations on this! Mark |
Thanks very much for all above discussion and it really works out now, special thanks to alskipp for developing nice codes, and publish the solution which works well on my devices now. I also thanks to PerMartin for his solution, this is the right answer. |
sorry but it not solve my problem, it happens again, so I add below codes to avoid NULL, seems it works fine now.
|
I tested it out and still have the same problem. Does anyone have a solution for that? thanks a lot in advance. |
I'm getting sporadically on different devices. iPhone 5s with 8.4 it happens everytime, but on an iPhone 6 running 9.1 it never happens. I'm getting sporadic crash reports from a device tester with an iPhone 6+ running 9.2. |
I'm experiencing the same issue, in my case steps to reproduce is to start recording in landscape mode and then quickly change orientation to portrait. Bad Access exception has the following back trace:
EDIT My temporary workaround is to scale down the pixel buffer size on low-end devices. |
I hade the same issue and @Rovemoon has the good solution, the crashing occurs significantly less often. Inside The writeVideoFrame method do this. |
I solve the problem. Please see first answer: |
I have the same issue, it happens at the same point from time to time. @alskipp ,have you found the final solution? please tell we,thank you, I had a week time for this crash. |
My answer to this issue -> http://stackoverflow.com/a/38044065/5608231 |
The stack overflow post (http://stackoverflow.com/questions/34086827/on-screen-recording-video-crashing-in-ios-8/38044065#38044065) seems to solve the issue for me too, but it now wont save the recording..... any ideas? |
AVAssetWriterInputPixelBufferAdaptor is not thread safe, so keep AVAssetWriterInputPixelBufferAdaptor not in multi threads. |
I have this issue too. My workaround was trying to retain the buffer: CVPixelBufferRef pixelBuffer = NULL; It seems to work without crash. |
Hi,
first of all, thanks for the code, it is really helpful.
I am getting a EXC_BAD_ACCESS error in this line:
BOOL success = [_avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:time];
inside writeVideoFrame method.
Do you have any clue about what would be wrong?
Thank you very much!
The text was updated successfully, but these errors were encountered: