Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 971355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:57:08+00:00 2026-05-16T02:57:08+00:00

I am creating a custom CCSprite class to display a custom image and set

  • 0

I am creating a custom CCSprite class to display a custom image and set its own position as well as handle other drawing tasks. Currently I have no other code running in the custom class but the initializer, which should set the image file and the position of the sprite. Here is my - (id)init method

- (id)init 
{
    if (!(self = [super initWithFile:@"runnerImage.png"]))
        return nil;
    //set our texture to the runner image ^^^
    //set our initial position
    CGSize size = [[CCDirector sharedDirector] winSize];
    self.position = CGPointMake(size.width/2, size.height-RUNNER_OFFSET); //centered x and offseted by RUNNER_OFFSET
    return self;
}

Currently the app crashes after running this code. (I have determined this with break points and commenting out lines.) Any idea why? This is the section I am calling it from:

myRunner = [[Runner alloc] init];
[self addChild:myRunner];   
//schedule an update each frame

That is in a CCLayer subclass’s - init method.

Here is the console log:

2010-07-31 09:16:32.730
CubeRacer[849:207] cocos2d: cocos2d
v0.99.4-rc2 2010-07-31 09:16:32.733
CubeRacer[849:207] cocos2d: Using
Director Type:CCDisplayLinkDirector
2010-07-31 09:16:33.064
CubeRacer[849:207] cocos2d: GL_VENDOR:
Apple Computer, Inc. 2010-07-31
09:16:33.065 CubeRacer[849:207]
cocos2d: GL_RENDERER: Apple Software
Renderer 2010-07-31 09:16:33.065
CubeRacer[849:207] cocos2d:
GL_VERSION: OpenGL ES-CM 1.1 APPLE
2010-07-31 09:16:33.066
CubeRacer[849:207] cocos2d:
GL_MAX_TEXTURE_SIZE: 2048 2010-07-31
09:16:33.067 CubeRacer[849:207]
cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH:
16 2010-07-31 09:16:33.068
CubeRacer[849:207] cocos2d: GL
supports PVRTC: YES 2010-07-31
09:16:33.068 CubeRacer[849:207]
cocos2d: GL supports BGRA8888
textures: NO 2010-07-31 09:16:33.071
CubeRacer[849:207] cocos2d: GL
supports NPOT textures: YES 2010-07-31
09:16:33.072 CubeRacer[849:207]
cocos2d: GL supports
discard_framebuffer: YES 2010-07-31
09:16:33.072 CubeRacer[849:207]
cocos2d: compiled with NPOT support:
NO 2010-07-31 09:16:33.073
CubeRacer[849:207] cocos2d: compiled
with VBO support in TextureAtlas : YES
2010-07-31 09:16:33.074
CubeRacer[849:207] cocos2d: compiled
with Affine Matrix transformation in
CCNode : YES 2010-07-31 09:16:33.074
CubeRacer[849:207] cocos2d: compiled
with Profiling Support: NO Program
received signal: “EXC_BAD_ACCESS”.

Thanks for any help!

Update
After some more research I found this may be a looping problem but I am unsure.
The superclasses initializer that I am calling calls [self init]. Would that call the - (id)init method of my subclass or of the CCSprite class? If it calls my subclass then that is the obvious problem. Check my comment for a link to the discussion I found of this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:57:08+00:00Added an answer on May 16, 2026 at 2:57 am

    I think your problem is that your method is the designated initializer -(id) init and then you call [super initWithFile:..] in it, which in turn calls -(id) init. Now because you have overridden -(id) init in your implementation, your version gets called and you’ll have an endless loop.

    That’s as far as I understand it. It’s definetely a bad idea to call a super method other than [super init] in the -(id) init method. Instead, rename your -(id) init method to -(id) initWithRunnerImage and you should be fine.

    The Apple docs give some more examples:
    http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocAllocInit.html#//apple_ref/doc/uid/TP30001163-CH22-SW8

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.