gpt4 book ai didi

iphone - self.layer renderInContext :context in drawRect method gives Bad Access in ipad but not in simulator

转载 作者:行者123 更新时间:2023-11-29 04:07:51 25 4
gpt4 key购买 nike

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

- (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。

它在设备中的模拟器或机器人崩溃中工作正常,我该如何解决这个问题?

最佳答案

您不应该在 drawRect: 中执行此操作,覆盖 drawRect: 的唯一原因是进行一些自定义绘图(但您不是这样做)。您也不应该在后台线程上调用 setNeedsDisplay ,这是一个只能从主线程调用的 GUI 方法。另外,根据您的 createBitmapContextOfSize: 方法和您可能需要释放位图上下文对象的环境。

关于iphone - self.layer renderInContext :context in drawRect method gives Bad Access in ipad but not in simulator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14909543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com