简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM