1

我有代码:
setUpMainImage.h:

#import "MainOpenGLView.h"

@interface MainOpenGLView (setUpMainImage)
- (void)loadImage;
@end

设置主图像.m:

#import "setUpMainImage.h"

@implementation MainOpenGLView (setUpMainImage)
- (void)loadImage {
    CIImage *_tempImage = [[CIImage alloc] initWithBitmapImageRep:_bottomTextureBitmap];
    CIFilter *_tempFilter = [CIFilter filterWithName:@"CIColorControls"];
    [_tempFilter setDefaults];
    [_tempFilter setValue:_tempImage forKey:@"inputImage"];
    [_tempFilter setValue:0 forKey:@"inputSaturation"];
    _tempImage = [_tempFilter valueForKey:@"outputImage"];
    _topTextureBitmap = [[NSBitmapImageRep alloc] initWithCIImage:_tempImage];
}
- (void)topTextureImage {
    float _topWide = _topTextureBitmap.pixelsWide;
    float _topHigh = _topTextureBitmap.pixelsHigh;
    glBindTexture(GL_TEXTURE_2D, _top_image_texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _topWide, _topHigh, 0, GL_RGBA, GL_UNSIGNED_BYTE, [_topTextureBitmap bitmapData]);

    NSLog(@"_topWide:%f, _topHigh:%f", _topWide, _topHigh);
}
@end

MainOpenGLView.h:

#import <Cocoa/Cocoa.h>
#import <QuartzCore/QuartzCore.h>
#import <Quartz/Quartz.h>
#import <OpenGL/OpenGL.h>

@interface MainOpenGLView : NSOpenGLView {
    NSBitmapImageRep *_topTextureBitmap;
    NSBitmapImageRep *_bottomTextureBitmap;
    GLuint _top_image_texture;
}
@end

MainOpenGLView.m:

#import "MainOpenGLView.h"
#import "setUpMainImage.h"

@implementation MainOpenGLView
    - (id)initWithCoder:(NSCoder *)coder {
        self = [super initWithCoder: coder];
        [self loadImage];
        [self topTextureImage];
        return self;
    }
@end

我得到错误
Thread 1: EXC_BAD_ACCESS(code=1, address=0x10)

setUpMainImage.m在线:

float _topWide = _topTextureBitmap.pixelsWide;

我正在使用 ARC(自动引用计数),所以我没有手动保留/释放任何对象。Maby ARC 发布_topTextureBitmap太早?

4

0 回答 0