OpenGL ES 텍스처를 생성 한 후 UIIMAGE를 해제하면 프로그램 충돌이 발생합니다.

StackOverflow https://stackoverflow.com/questions/1411410

  •  05-07-2019
  •  | 
  •  

문제

지금은이 튜토리얼을 따랐습니다.

http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-part-6_25.html

UIIMAGE를 해제하려고 시도하면 작동하지 않습니다. 이제 나는 UIIMAGE를 인스턴스 변수로 만들어서 유지했습니다. 나는 그것을 자동 제출로 만들지 않습니다. 그러나 문제는 때때로 내 질감을 삭제하고 싶다는 것입니다. 그 uiimage를 풀어야합니다. 그렇지 않으면 누출이있을 것입니다. (성능 도구 누출은 uiimage가 누출을 일으킨다 고보고하지만) UIIMAGE를 해제하면 exc_bad_access를 얻을 것입니다. 그리고 나는 그들을 그리거나 어디서나 접근하지도 않습니다. 이 프로그램은 출시 된 곳에서 바로 충돌합니다.

#0  0x30011940 in objc_msgSend ()
#1  0x302395f4 in CFGetTypeID ()
#2  0x308f480c in -[UIImage(UIImageDeprecated) imageRef] ()
#3  0x308f4ae0 in SharedIdentifierForImage ()
#4  0x308f4a30 in _UISharedImageDealloc ()
#5  0x308f4964 in -[UIImage dealloc] ()
#6  0x30236b78 in -[NSObject release] ()
#7  0x0000a374 in -[Texture dealloc] (self=0x184b30, _cmd=0x300f7fd0) at /Users/akaraphan/Desktop/Competition/TrapRoom/Classes/Texture.m:329
#8  0x30236b78 in -[NSObject release] ()
#9  0x30235f24 in CFRelease ()
#10 0x302043bc in __CFTypeCollectionRelease ()
#11 0x30205dac in __CFArrayReleaseValues ()
#12 0x30205c18 in __CFArrayDeallocate ()
#13 0x30236020 in _CFRelease ()
#14 0x30235efe in CFRelease ()
#15 0x3054836a in -[NSCFArray release] ()
#16 0x00011658 in -[GameSprite dealloc] (self=0x1838d0, _cmd=0x300f7fd0) at /Users/akaraphan/Desktop/Competition/TrapRoom/Classes/GameSprite.m:40
...
...

Texture.m의 329 행은 UIIMAGE를 해제하는 곳입니다.

내 코드는 자습서와 약간 다르지만 매우 유사하게 작동해야합니다.

- (id) initFromImage: (NSString*)imageFile{

    if (self = [super init]){

        path = [[NSBundle mainBundle] pathForResource:imageFile ofType:@"png"];
        texData = [[NSData alloc] initWithContentsOfFile:path];
        img = [[UIImage alloc] initWithData:texData];

        CGImageRef image = img.CGImage;

        width = CGImageGetWidth(image);
        height = CGImageGetHeight(image);

        if (image){
            int tempWidth = (int)width, tempHeight = (int)height;

            if ((tempWidth & (tempWidth - 1)) != 0 ){
                NSLog(@"CAUTION! width is not power of 2. width == %d", tempWidth);
            }else if ((tempHeight & (tempHeight - 1)) != 0 ){
                NSLog(@"CAUTION! height is not power of 2. height == %d", tempHeight);
            }else{
                GLubyte *spriteData = (GLubyte*) calloc(width * 4, height * 4);

                CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width*4, CGImageGetColorSpace(image), kCGImageAlphaPremultipliedLast);

                CGContextDrawImage(spriteContext, CGRectMake(0.0, 0.0, width, height), image);

                CGContextRelease(spriteContext);

                glGenTextures(1, &GLtexture);

                glBindTexture(GL_TEXTURE_2D, GLtexture);

                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);

                free(spriteData);

                CGImageRelease(image);

                NSLog(@"Texture %d", GLtexture);

            }

        }else NSLog(@"ERROR: Image not loaded...");

        return self;
    }
    return nil;
}

무엇이 잘못되었는지 알 수 있다면 저를 안내 해주세요. 고맙습니다.

도움이 되었습니까?

해결책

어떻게 든 제거

CGImageRelease(image)

문제를 해결했습니다. 그 후에는 아무런 문제없이 uiimage를 제거 할 수 있으며 누출도 없습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top