AFathi / ARVideoKit

Capture & record ARKit videos ๐Ÿ“น, photos ๐ŸŒ„, Live Photos ๐ŸŽ‡, and GIFs ๐ŸŽ†.
Apache License 2.0
1.63k stars 225 forks source link

memory isssue cause crash (Terminated due to memory issue) #55

Closed UninhibitedSoul closed 6 years ago

UninhibitedSoul commented 6 years ago

DebugInfo

func frame(didRender buffer: CVPixelBuffer, with time: CMTime, using rawBuffer: CVPixelBuffer) { if capture != nil { capture?.didCaptureCVPixelBufferRef(buffer, time: time, usingRowBuffer: rawBuffer) } } I use WebRTC capture and send CVPixelBuffer. I update ARVideoKit.framework yesterday afternoon , and memory isssue cause crash . It seems to be in Function: CVPixelBufferCreate , CVPixelBufferBacking::initWithPixelBufferDescription,CVPixelBufferStandardMemoryLayout

AFathi commented 6 years ago

@UninhibitedSoul, which version of ARVideoKit are you using?

UninhibitedSoul commented 6 years ago

@AFathi version 1.3.1

AFathi commented 6 years ago

@UninhibitedSoul, will investigate the issue and get back to you soon

UninhibitedSoul commented 6 years ago

If i use extension to conform protocol 'RenderARDelegate',I send CVPixelBuffer to webrtc.Within half a minute, the memory will exceed 1G. Then my app Crash.


//MARK: RenderARDelegate
extension RARShareARViewController : RenderARDelegate {

    func frame(didRender buffer: CVPixelBuffer, with time: CMTime, using rawBuffer: CVPixelBuffer) {
        if capture != nil {
            capture?.didCaptureCVPixelBufferRef(buffer, time: time, usingRowBuffer: nil)
        }
    }
}

If i conform protocol 'RenderARDelegate' by class, not by extension.The memory will not exceed 200M. My app won't crash.


class RARShareARViewController : UIViewController,RenderARDelegate {

       .
       .
       . 

    func frame(didRender buffer: CVPixelBuffer, with time: CMTime, using rawBuffer: CVPixelBuffer) {
        if capture != nil {
            capture?.didCaptureCVPixelBufferRef(buffer, time: time, usingRowBuffer: nil)
        }
    }
}

Is it a swift extension bug?

AFathi commented 6 years ago

@UninhibitedSoul, thanks for clarifying this to me. I believe the issue may be occurring due to the fact that frame(didRender buffer: CVPixelBuffer, with time: CMTime, using rawBuffer: CVPixelBuffer) is executed in an extension of RecordAR.

I'd suggest to go to RecordAR.swift file located at /ARVideoKit/Sources/ then scroll down all the way to the following block of code:

//MARK: - Internal AR Video Frames Rendering
@available(iOS 11.0, *)
internal extension RecordAR {
    @objc internal func renderFrame() {
           ......
           ......
           ......
     }
}

then cut (cmd+x) the renderFrame() function and paste it inside the original RecordAR class.

I have attached the RecordAR file to this comments that includes that changes I mentioned above. Feel free download it and replace the current file you have with the new one :).

Note:- Make sure to change the file extension to .swift.

RecordAR.txt

AFathi commented 6 years ago

@UninhibitedSoul, please let me know whether the changes I suggested fixed the issue you're having or not.

UninhibitedSoul commented 6 years ago

I'm so sorry๏ผI can't reappear this bug. I tried to use extension to conform protocol 'RenderARDelegate'. I tried to roll back the code. But,I can't reappear this bug. The memory will not exceed 200M. My app won't crash. Thanks for you help.

fukemy commented 1 year ago

Hi, Can I ask a question: How did you populate the frame with WebRTC?