0

iOS がアプリケーションを過酷な方法でクラッシュさせる理由を突き止めようとしています (クラッシュ ログがなく、スピナーがしばらく表示された状態で黒い画面が表示されてすぐにシャットダウンします)。Quartz を使用して CALayer のコンテンツをレンダリングすると発生します。メモリの問題が疑われましたが (デバイスでのテスト時にのみ発生します)、メモリ ログと計測器の割り当てログは問題ないようです。致命的な機能を通過させてください:

- (void)renderTiles{

    if (rendering) {
        //NSLog(@"====== RENDERING TILES SKIP =======");
        return;
    }
    rendering = YES;



    CGRect b = tileLayer.bounds;
    CGSize s = b.size;
    CGFloat imageScale = [[UIScreen mainScreen] scale];
    s.height *= imageScale;
    s.width *= imageScale;

    dispatch_async(queue, ^{

        NSLog(@"");
         NSLog(@"====== RENDERING TILES START =======");

        NSLog(@"1. Before creating context");
        report_memory();

        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        NSLog(@"2. After creating color space");
        report_memory();

        NSLog(@"3. About to create context with size: %@", NSStringFromCGSize(s));
        CGContextRef ctx = CGBitmapContextCreate(NULL, s.width, s.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);

        NSLog(@"4. After creating context");
        report_memory();

        CGAffineTransform flipTransform = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, s.height);
        CGContextConcatCTM(ctx, flipTransform);

        CGRect tileRect = CGRectMake(0, 0, tileImageScaledSize.width, tileImageScaledSize.height);
        CGContextDrawTiledImage(ctx, tileRect, tileCGImageScaled);

        NSLog(@"5. Before creating cgimage from context");
        report_memory();

        CGImageRef cgImage = CGBitmapContextCreateImage(ctx);
        NSLog(@"6. After creating cgimage from context");
        report_memory();

        dispatch_sync(dispatch_get_main_queue(), ^{
            tileLayer.contents = (id)cgImage;        
        });

        NSLog(@"7. After asgning tile layer contents = cgimage");
        report_memory();

        CGColorSpaceRelease(colorSpace);
        CGContextRelease(ctx);
        CGImageRelease(cgImage);

        NSLog(@"8. After releasing image and context context");
        report_memory();


        NSLog(@"====== RENDERING TILES END =======");
        NSLog(@"");
        rendering = NO;

    });
}

ログは次のとおりです。

====== RENDERING TILES START =======
1. Before creating context
    Memory in use (in bytes): 28340224 / 519442432 (5.5%)
2. After creating color space
    Memory in use (in bytes): 28340224 / 519442432 (5.5%)
3. About to create context with size: {6324, 5208}
4. After creating context
    Memory in use (in bytes): 28344320 / 651268096 (4.4%)
5. Before creating cgimage from context
    Memory in use (in bytes): 153649152 / 651333632 (23.6%)
6. After creating cgimage from context
    Memory in use (in bytes): 153649152 / 783159296 (19.6%)
7. After asgning tile layer contents = cgimage
    Memory in use (in bytes): 153653248 / 783253504 (19.6%)
8. After releasing image and context context
     Memory in use (in bytes): 21688320 / 651288576 (3.3%)
====== RENDERING TILES END =======

アプリケーションがランダムな場所でクラッシュします。関数の en に到達するときもあれば、ランダムなステップに到達するときもあります。

どの方向に解決策を探すべきですか? GDC が問題を引き起こしている可能性はありますか? それとも、コンテキスト サイズまたは一部のコア アニメーションの基になる参照でしょうか?

4

1 に答える 1

0

レンダリングされたコンテキスト サイズを正確にデバッグして実験した結果、メモリ関連の問題であることが判明しました。解決策は、コンテキストのサイズを最大幅 2048、高さ 1024 に制限することでした。

于 2012-09-12T21:36:16.597 に答える