Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instance variable used while 'self' is not set to the result of

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?

like image 353
VansFannel Avatar asked Dec 27 '22 10:12

VansFannel


1 Answers

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.

like image 193
tarmes Avatar answered Jan 11 '23 23:01

tarmes