【问题标题】:self.layer renderInContext:context in drawRect method gives Bad Access in ipad but not in simulatorself.layer renderInContext:context in drawRect 方法在 ipad 中给出了 Bad Access 但在模拟器中没有
【发布时间】:2013-02-16 23:00:28
【问题描述】:

我正在使用一个应用程序并在其中进行视频录制。现在我要做的是捕获图像然后创建视频代码如下

- (void) drawRect:(CGRect)rect {
    NSDate* start = [NSDate date];

    CGContextRef context = [self createBitmapContextOfSize:self.frame.size];
    NSLog(@"context value %@",context);

    [self.layer renderInContext:context];

    CGImageRef cgImage = CGBitmapContextCreateImage(context);
    UIImage* background = [UIImage imageWithCGImage: cgImage];
    CGImageRelease(cgImage);
    self.currentScreen = background;


    if (_recording) {
        float millisElapsed = [[NSDate date] timeIntervalSinceDate:startedAt] * 1000.0;
        [self writeVideoFrameAtTime:CMTimeMake((int)millisElapsed, 1000)];

    }

      float processingSeconds = [[NSDate date] timeIntervalSinceDate:start];
      delayRemaining = (1.0 / self.frameRate) - processingSeconds;


      [self performSelectorInBackground:@selector(setNeedsDisplay) withObject:nil];

}

现在的问题是该方法是递归调用的,当停止录制时,它会给我 Exc_Bad_Access。

它在设备中的模拟器机器人崩溃中运行良好,我该如何解决这个问题?

【问题讨论】:

    标签: iphone ios objective-c xcode


    【解决方案1】:

    你不应该在drawRect: 中这样做,覆盖drawRect: 的唯一原因是做一些自定义绘图(你不是)。你也不应该在后台线程调用setNeedsDisplay,这是一个只能从主线程调用的GUI方法。还取决于您的 createBitmapContextOfSize: 方法和您的环境,您可能需要释放位图上下文对象。

    【讨论】:

    • 当我在主线程上使用这个 setneedsdisplay 时,应用程序给了我 SIGBART :[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    • 2012-08-21
    • 2012-06-28
    • 1970-01-01
    • 2015-12-10
    • 2011-05-10
    • 1970-01-01
    相关资源
    最近更新 更多