I'm working with SGAREnvioroment, and I get the following error:
Instance variable used while 'self' is not set to the result of '[(super or self) init...]'
In this piece of code:
@interface SG3DOverlayView (Private)
- (id) initGLES;
- (void) drawView;
- (BOOL) createFramebuffer;
- (void) destroyFramebuffer;
- (void) clearTouches;
@end
@implementation SG3DOverlayView
+ (Class) layerClass
{
return [CAEAGLLayer class];
}
-(id) initWithFrame:(CGRect)frame
{
if(self = [super initWithFrame:frame]) {
self = [self initGLES];
}
return self;
}
-(id) initGLES
{
self.multipleTouchEnabled = YES;
self.exclusiveTouch = YES;
CAEAGLLayer *eaglLayer = (CAEAGLLayer*) self.layer;
eaglLayer.opaque = YES;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
nil];
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer]) {
[self release];
return nil;
}
self.backgroundColor = [UIColor clearColor];
mainSubview = [[UIView alloc] initWithFrame:self.frame];
mainSubview.backgroundColor = [UIColor clearColor];
animationInterval = 1.0;
pinchTimer = nil;
dragging = NO;
currentSphereRadius = 0.0;
[self clearTouches];
return self;
}
I get the "error" here:
if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer]) {
But, as you can see, self is setup on -(id) initWithFrame:(CGRect)frame
, and -(id) initGLES
is private, so it is always called from -(id) initWithFrame:(CGRect)frame
.
So, may I have to do something to fix it?
Don't prefix your function name with init - the analyzer assumes that it's an initializer, and in this case it isn't.
Also, the function shouldn't return self if it isn't initialising it. Make it void.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With