Coder Social home page Coder Social logo

Comments (41)

PerMartin avatar PerMartin commented on June 18, 2024 1

Hi
I have had the same problem, getting EXC_BAD_ACCESS.
I solved by using XCodes Analyze function. It pointed out, that there was a potential memory leak in "createPixelBufferAndBitmapContext" in the line "return bitmapContext;"
I changed the code, so that the functionality from createPixelBufferAndBitmapContext was put into the calling function "writeVideoFrame", and now it seems to be working.

from asscreenrecorder.

tobira avatar tobira commented on June 18, 2024

i getting the same error,any solution now?

from asscreenrecorder.

alskipp avatar alskipp commented on June 18, 2024

Hi folks,
Sorry for the late response to this issue. Do you have any more details to help me track down the issue? Does this occur with the demo app, or with your own use case? Does it crash immediately, or does it record for a while first? I'll investigate the issue, but any further details would be very helpful (extra error info, stack trace etc).

Al

from asscreenrecorder.

alskipp avatar alskipp commented on June 18, 2024

In the - (void)writeVideoFrame method towards the end there is the following code:

// 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

from asscreenrecorder.

tobira avatar tobira commented on June 18, 2024

It occur with my own app.Sometimes it work perfect.It crash both immediately and record for a while.
the "time" always be null when "BOOL success = [_avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:time];" called.
I have tried to replacing those code as your suggestion,unfortunately it didn't work.

from asscreenrecorder.

tobira avatar tobira commented on June 18, 2024

By the way,will you adding sounds?

from asscreenrecorder.

alskipp avatar alskipp commented on June 18, 2024

Hi @tobira,
With regards to sound recording, this is not currently planned due to time constraints. Take a look at my response to #3, I give a few suggestions which might point you in the right direction.
Thanks for trying the suggested fix, but sorry it didn't work. The fact the time variable becomes null is pretty suspicious, I'm not sure why this should be the case, I'll see if I can discover why.

from asscreenrecorder.

tobira avatar tobira commented on June 18, 2024

Thanks for your suggestions,that is helpful!

from asscreenrecorder.

nihtin9mk avatar nihtin9mk commented on June 18, 2024

Hi @tobira @alskipp ...Could you find out this issue ?
I am experiencing the same issue and stuck in my app.

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];

from asscreenrecorder.

alskipp avatar alskipp commented on June 18, 2024

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.

from asscreenrecorder.

nihtin9mk avatar nihtin9mk commented on June 18, 2024

HI @alskipp - please try to record a screen and after finishes quit the app and again start recording, suddenly it crashes at times.
Hopefully you can find the issue and solve this as you are the creator of this awesome control.

An the issue is not related to second video capture, I have described in issue #5.

from asscreenrecorder.

alskipp avatar alskipp commented on June 18, 2024

Hi @nihtin9mk,
I'll have a bit more spare time this weekend and I'll do my best to locate the problem. I'll try the record, quit, then record to see if I can reproduce the crash.

from asscreenrecorder.

nihtin9mk avatar nihtin9mk commented on June 18, 2024

So kind of you. Thank you @alskipp.

I am also trying to find out the issue.

from asscreenrecorder.

alskipp avatar alskipp commented on June 18, 2024

Just tried the record, quit, record routine several times with my own app - I've not yet been able to reproduce the crash πŸ˜•

from asscreenrecorder.

nihtin9mk avatar nihtin9mk commented on June 18, 2024

That is bit strange - Please check my attached image
screen shot 2014-09-18 at 7 28 22 pm

from asscreenrecorder.

berio avatar berio commented on June 18, 2024

Hi, sorry for being out,
I was in holidays.
Yes, that is exactly the same error that I have. I couldn't find any solution yet.
I would be more than glad if it could be fixed. This piece of code is pretty helpful.

from asscreenrecorder.

berio avatar berio commented on June 18, 2024

I just updated xcode and ipad to ios8 and the EXC_BAD_ACCESS error disappeared. Everything works now like a charm!

from asscreenrecorder.

alskipp avatar alskipp commented on June 18, 2024

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.

from asscreenrecorder.

nihtin9mk avatar nihtin9mk commented on June 18, 2024

Hi @alskipp - waiting for your solution.

from asscreenrecorder.

alskipp avatar alskipp commented on June 18, 2024

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,
Al

from asscreenrecorder.

nihtin9mk avatar nihtin9mk commented on June 18, 2024

Hi @alskipp..I know you are so busy, but could you figure out the issue. I am trying to fix it.
@PerMartin - Hi man, good to hear that you fixed that - can you post some codes.

from asscreenrecorder.

nihtin9mk avatar nihtin9mk commented on June 18, 2024

Hi @alskipp .. Waiting for your response.

from asscreenrecorder.

alskipp avatar alskipp commented on June 18, 2024

Apologies for the delay, but things have been a bit hectic lately.

I've added an experimental branch to the repository:
https://github.com/alskipp/ASScreenRecorder/tree/experimental

Could you check this out and see if it works for you? All I've done is create the CGContext in thewriteVideoFrame method as suggested by @PerMartin. The static analyser is now happy - let me know how you get on.

Al

from asscreenrecorder.

nihtin9mk avatar nihtin9mk commented on June 18, 2024

Thank you @alskipp , for the help -
I have tried your solution, but unfortunately it is getting crashed at the point
BOOL success = [_avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:time];

from asscreenrecorder.

kellyts avatar kellyts commented on June 18, 2024

I have also tried the experimental branch and have the same crash:
BOOL success = [_avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:time];
Has there been any progress in resolving this?

from asscreenrecorder.

ranjk89 avatar ranjk89 commented on June 18, 2024

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.

from asscreenrecorder.

manderson-productions avatar manderson-productions commented on June 18, 2024

@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
Crashed: ASScreenRecorder.append_queue
EXC_BAD_ACCESS KERN_PROTECTION_FAILURE at 0x0bb49000
raw
0
libsystem_platform.dylib
_platform_memmove + 485
1
2
CoreMedia
FigNEAtomWriterAppendData + 52
3
CoreMedia
sbufAtom_appendAtomWithMemoryBlock + 64
4
CoreMedia
sbufAtom_createSerializedDataForPixelBuffer + 452
5
CoreMedia
FigRemote_CreateSerializedAtomDataForPixelBuffer + 214
6
MediaToolbox
remoteWriter_AddPixelBuffer + 88
7
AVFoundation
-[AVFigAssetWriterTrack addPixelBuffer:atPresentationTime:error:] + 104
8
AVFoundation
-[AVAssetWriterInputWritingHelper appendPixelBuffer:withPresentationTime:] + 120
9
AVFoundation
-[AVAssetWriterInput _appendPixelBuffer:withPresentationTime:] + 80
10
AVFoundation
-[AVAssetWriterInputPixelBufferAdaptor appendPixelBuffer:withPresentationTime:] + 90
11
Spring
ASScreenRecorder.m line 379
__35-[ASScreenRecorder writeVideoFrame]_block_invoke309
12 libdispatch.dylib
_dispatch_call_block_and_release + 10
13
libdispatch.dylib
_dispatch_queue_drain + 952
14
libdispatch.dylib
_dispatch_queue_invoke + 84
15
libdispatch.dylib
_dispatch_root_queue_drain + 338
16
libdispatch.dylib
_dispatch_worker_thread3 + 94
17 libsystem_pthread.dylib
_pthread_wqthread + 668

from asscreenrecorder.

manderson-productions avatar manderson-productions commented on June 18, 2024

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

from asscreenrecorder.

Rovemoon avatar Rovemoon commented on June 18, 2024

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.

from asscreenrecorder.

Rovemoon avatar Rovemoon commented on June 18, 2024

sorry but it not solve my problem, it happens again, so I add below codes to avoid NULL, seems it works fine now.

            if (pixelBuffer != NULL)
            {
                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);
            }

from asscreenrecorder.

andrewzeus avatar andrewzeus commented on June 18, 2024

I tested it out and still have the same problem. Does anyone have a solution for that? thanks a lot in advance.

from asscreenrecorder.

mineshpurohit avatar mineshpurohit commented on June 18, 2024

Hello All,
I am also getting the same issue. is any one able to solve that issue then please share resolution.
Thanks in advance.

screen shot 2015-12-29 at 6 15 18 pm

from asscreenrecorder.

jgorecki-zz avatar jgorecki-zz commented on June 18, 2024

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.

from asscreenrecorder.

azubala avatar azubala commented on June 18, 2024

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:

* thread #6: tid = 0x74a32, 0x39bd61dc libsystem_platform.dylib`_platform_memmove$VARIANT$CortexA9 + 160, queue = 'ASScreenRecorder.append_queue', stop reason = EXC_BAD_ACCESS (code=1, address=0x2bfb000)
    frame #0: 0x39bd61dc libsystem_platform.dylib`_platform_memmove$VARIANT$CortexA9 + 160
    frame #1: 0x286607ac CoreMedia`FigNEAtomWriterAppendData + 52
    frame #2: 0x28660664 CoreMedia`sbufAtom_appendAtomWithMemoryBlock + 64
    frame #3: 0x2865f0aa CoreMedia`sbufAtom_createSerializedDataForPixelBuffer + 438
    frame #4: 0x2865edea CoreMedia`FigRemote_CreateSerializedAtomDataForPixelBuffer + 142
    frame #5: 0x29b54ac4 MediaToolbox`remoteWriter_AddPixelBuffer + 88
    frame #6: 0x265ee1f4 AVFoundation`-[AVFigAssetWriterTrack addPixelBuffer:atPresentationTime:error:] + 104
    frame #7: 0x265ea79c AVFoundation`-[AVAssetWriterInputWritingHelper appendPixelBuffer:withPresentationTime:] + 120
    frame #8: 0x265e854a AVFoundation`-[AVAssetWriterInput _appendPixelBuffer:withPresentationTime:] + 82
    frame #9: 0x265ed38a AVFoundation`-[AVAssetWriterInputPixelBufferAdaptor appendPixelBuffer:withPresentationTime:] + 90

EDIT
I performed number of measurements using Instruments: Allocations, Leaks and Zombies and there's no clear indication what is the problem. However I have a strong feeling that this crash is happening due to the temporal excessive memory usage - in my case it's easily to reproduce on older devices, e.g. iPod.

My temporary workaround is to scale down the pixel buffer size on low-end devices.

from asscreenrecorder.

JeffHyde avatar JeffHyde commented on June 18, 2024

I hade the same issue and @Rovemoon has the good solution, the crashing occurs significantly less often. Inside The writeVideoFrame method do this.
screen shot 2016-02-04 at 3 51 12 pm
.

from asscreenrecorder.

jabson avatar jabson commented on June 18, 2024

I solve the problem.

Please see first answer:
https://stackoverflow.com/questions/34086827/on-screen-recording-video-crashing-in-ios-8/36598298#36598298

from asscreenrecorder.

weitiedan avatar weitiedan commented on June 18, 2024

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.

from asscreenrecorder.

msobiepanek-uz avatar msobiepanek-uz commented on June 18, 2024

My answer to this issue -> http://stackoverflow.com/a/38044065/5608231
I don't see this error anymore.

from asscreenrecorder.

MrChrisBarker avatar MrChrisBarker commented on June 18, 2024

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?

from asscreenrecorder.

xjwang1126 avatar xjwang1126 commented on June 18, 2024

AVAssetWriterInputPixelBufferAdaptor is not thread safe, so keep AVAssetWriterInputPixelBufferAdaptor not in multi threads.

from asscreenrecorder.

ameinc avatar ameinc commented on June 18, 2024

I have this issue too. My workaround was trying to retain the buffer:

CVPixelBufferRef pixelBuffer = NULL;
CVPixelBufferRetain(pixelBuffer); // hope to retain the buffer
CGContextRef bitmapContext = [self createPixelBufferAndBitmapContext:&pixelBuffer];

It seems to work without crash.

from asscreenrecorder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.