我有代码:
setUpMainImage.h:
#import "MainOpenGLView.h"
@interface MainOpenGLView (setUpMainImage)
- (void)loadImage;
@end
setUpMainImage.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
?