iOS Ошибка подтверждения GPUImage Framebuffer - PullRequest
0 голосов
/ 10 апреля 2020

Я записываю видео во время отображения некоторого текста и графики, наложенных на видео, с помощью библиотеки GPUImage, и кажется, что она работает нормально в течение 5 минут или около того, пока приложение внезапно не вылетает, указывая на код

NSAssert(framebufferReferenceCount > 0, @"Tried to overrelease a framebuffer, did you forget to call -useNextFrameForImageCapture before using -imageFromCurrentFramebuffer?");

Вот код, который я использую для отображения текста поверх видео. Заранее спасибо.

    GPUImageView *filterView = (GPUImageView *)self.view;
    filter = [[GPUImageBrightnessFilter alloc]init];
    [(GPUImageBrightnessFilter*)filter setBrightness:0.0];
    [captureDevice addTarget:filter];
    blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
    blendFilter.mix = 1.0;
    uiElementInput = [[GPUImageUIElement alloc] initWithView:overlayView];
    [filter addTarget:blendFilter];
    [uiElementInput addTarget:blendFilter];
    [blendFilter addTarget:filterView];
    NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
    timeFormatter.dateFormat = @"yyyy MM dd-HH:mm a";
    NSCalendarUnit units = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
    units |= NSCalendarUnitHour | NSCalendarUnitMinute;
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    __unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput;
    __weak typeof(self) weakSelf = self;
    [filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime) {
        @autoreleasepool {
            if ([[manager setting] displayTimeEnabled] && shouldUpdateTime) {
                NSDate *date = [NSDate date];
                NSDateComponents *currentComponents = [gregorian components:units fromDate:date];
                date = [gregorian dateFromComponents:currentComponents];
                NSString *currentTimeString = [timeFormatter stringFromDate:date];
                weakSelf.timeLabel.text = currentTimeString;
                shouldUpdateTime = NO;
            }
            if ([[manager setting] gpsEnabled] && coordinatesHaveChanged) {
                weakSelf.coordinatesLabel.text = weakSelf.coordinatesStr;
                coordinatesHaveChanged = NO;
            }
            if (weakSelf.gForceEnabled) {
                [weakSelf.xLabel setText:[NSString stringWithFormat:@"%.1f",weakSelf.y]];
                [weakSelf.yLabel setText:[NSString stringWithFormat:@"%.1f",weakSelf.z]];
            }
            if (weakSelf.connected) {
                for (int i=0; i < [weakSelf.gaugeArr count]; i++) {
                    UILabel * l = [weakSelf.labelArr objectAtIndex:i];
                    NSString * strVal;
                    GaugeView2 * gv = [weakSelf.gaugeArr objectAtIndex:i];
                    if (gv.maxUnit > 20.0 && gv.maxUnit < 2000) {
                        strVal = [NSString stringWithFormat:@"%d",(int)gv.getVal];
                    }
                    else if (gv.maxUnit >= 2000) {
                        strVal = [NSString stringWithFormat:@"%.1f",gv.getVal/1000.0f];
                    }
                    else if (gv.maxUnit <= 3.0) {
                        strVal = [NSString stringWithFormat:@"%.2f",gv.getVal];
                    }
                    else {
                        strVal = [NSString stringWithFormat:@"%.1f",gv.getVal];
                    }
                    l.text = strVal;
                }
                if (weakSelf.isRaceMode) {

                    weakSelf.timerLabel.text = weakSelf.raceTimerStr;
                    if (weakSelf.shouldUpdateLap) {
                        [weakSelf.lapLabel setText:[NSString stringWithFormat:@"%d",weakSelf.lapCount]];
                        weakSelf.shouldUpdateLap = NO;
                    }
                }
            }
        }

        [weakUIElementInput update];
    }];
...