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 9125713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:52:00+00:00 2026-06-17T06:52:00+00:00

I am using Objective-c and cocos2d, and I am getting the strangest error when

  • 0

I am using Objective-c and cocos2d, and I am getting the strangest error when combining two pieces of seemingly unrelated code.

The suspected code in the init of a layer.

/* sprite setup */

CCSprite *sprite = [ [ [ StaticSprite alloc ] initWithSheetName: @"001-Fighter01" atPosition: ccp( 200, 200 ) withColumn: 0 withRow: 1 ] autorelease ];
[ map.spriteLayer addChild: sprite ];
CCSprite *sprite2 = [ [ [ StaticSprite alloc ] initWithSheetName: @"001-Fighter01" atPosition: ccp( 250, 200 ) withColumn: 0 withRow: 1 ] autorelease ];
[ map.spriteLayer addChild: sprite2 ];
CCSprite *sprite3 = [ [ [ StaticSprite alloc ] initWithSheetName: @"001-Fighter01" atPosition: ccp( 200, 250 ) withColumn: 0 withRow: 1 ] autorelease ];
[ map.spriteLayer addChild: sprite3 ];

/* ui setup */

// dpad
dPadUI = [ DPad node ];
[ self addChild: dPadUI ];

The DPad creation is giving the error CGImageProviderCreate: invalid image provider size: 55 x 36, which causes a crash. The weird part is, if I remove the sprite setup code, the DPad code works fine, and if I remove the DPad code, the sprite code works fine, but somehow when both are present I get the error.

StaticSprite is a fairly simple extension of the CCSprite class:

@implementation StaticSprite

- ( id ) initWithSheetName: ( NSString * ) sheetName atPosition: ( CGPoint ) initPosition withColumn: ( int ) column withRow: ( int ) row {

    // setup frames
    [ [ CCSpriteFrameCache sharedSpriteFrameCache ] addSpriteFramesWithFile: [ NSString stringWithFormat: @"%@.plist", sheetName ] ];

    if ( self = [ super initWithSpriteFrameName:[ NSString stringWithFormat: @"%@-%d,%d.png", sheetName, column, row ] ] ) {

        int halfSize = [ Geometry spriteHalfSizeFromRect: [ self boundingBox ] ];
        self.anchorPoint = ccp( .5, halfSize / [ self boundingBox ].size.height );

        self.position = initPosition;
        self.zOrder = -self.position.y;
    }

    return self;
}

@end

DPad is also a fairly simple extension of a CCSprite:

@implementation DPad

- ( id ) init {
    if ( self = [ super initWithFile: @"dPad.png" ] ) {
        self.anchorPoint = ccp( 18 / [ self boundingBox ].size.width, .5 );
        self.visible = false;
        self.blendFunc = ( ccBlendFunc ) { GL_SRC_ALPHA, GL_ONE };
        self.opacity = 64;
    }
    return self;
}

- ( void ) activateWithDirection: ( double ) angle {
    self.visible = true;
    [ self setRotation: CC_RADIANS_TO_DEGREES( -angle ) ];
}

- ( void ) deactivate {
    self.visible = false;
}

@end

I seem to be able to add as many static sprites with different images with no issue, and the DPad image is pretty small. Why would both of these sections of code work alone, but when in the same app together, they cause the weird error?

I have tried include renaming the DPad init method to initDefault.

EDIT

I stepped through the cocos2d code and found that the error happens right here. After the error, image turns to nil.

UIImage *image = [[UIImage alloc] initWithContentsOfFile:fullpath];

I know it is finding the image, because it prints out the image’s size in its error in the log. I cannot seem to find anyone else who has seen this error message on Google.

Currently I am working around this bug by placing the DPad code before all of the Sprite creation code, which seems to stop the bug from occurring, but I would really like to figure out why this is happening. Sporadic bugs make me very nervous until I can figure them out.

  • 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-06-17T06:52:01+00:00Added an answer on June 17, 2026 at 6:52 am

    Wow, so this is a weird one. Somewhere in my code i had max instead of MAX, and this was causing all types of havoc throughout my code. Three unexplained bugs that I have been lamenting over for the past few days all went away after that one change. For some reason using max in my code was causing everything from this, to making floatValue return nil unexplainedly, to making adding an object to an array cause an unexplained bad access error.

    Thanks to all who helped.

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

Sidebar

Related Questions

I have two major classes in objective C using cocos2D, DebugZoneLayer and HeroClass. Using
I'm using cocos2d with objective C. I have a class called CrystalineBubble that is
I'm using cocos2d-x [lua binding] to port my cocos2d [objective-c] game and I had
I am new to Objective-C. I am currently working on a game using Cocos2D
I've started using Objective-C blocks today. I wrote the following code: NSArray *array =
I'm used to using Objective-C protocols in my code; they're incredible for a lot
I have been learning and using Objective-C and cocos2d (iOS game-engine) for a couple
Here's my code: @interface Game : Layer // this is from cocos2d { int
I'm working on an iPhone app in objective-c also using cocos2d for graphics. I
Hi all im working on an ipad app using cocos2d objective c and box2d.

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.