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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:03:17+00:00 2026-05-25T10:03:17+00:00

Let me explain it in depth, when ever if(CGRectContainsPoint([hole1 boundingBox], ball1.position)) condition goes true,

  • 0

Let me explain it in depth, when ever if(CGRectContainsPoint([hole1 boundingBox], ball1.position)) condition goes true, i do lots of stuffs, like unscheduled, a selector, destroying a ball body calling an animation (please refer Code below)etc. This work properly most of the time. But sometimes when ball is really near to hole(just touching the hole but but not enough to make the above condition true), or is been throws towards the hole really fast speed, then application got terminated. I have checked, by commenting many actions which are been performed in this section, but got nothing helpful, application keep terminating when some efforts are been done to make it terminate.

if(CGRectContainsPoint([hole1 boundingBox], ball1.position))
{
    ballBody->SetLinearVelocity(b2Vec2(0.0f,0.0f));
    ballBody->SetAngularVelocity(0.0f);

    [self unschedule:@selector(tick:)];
    self.isTouchEnabled = NO;

    [self removeChild:ball1 cleanup:YES];
    world->DestroyBody(ballBody);

    // create the sprite sheet
    CCSpriteSheet *spriteSheet;

    GolfBallsAppDelegate *appDelegate = (GolfBallsAppDelegate *)[[UIApplication sharedApplication] delegate];
    if([appDelegate.ballValue isEqualToString:@"cricketball"])
    {
        spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"cricket_ball_strip.png"];
    }
    else if([appDelegate.ballValue isEqualToString:@"ironball"])
    {
        spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"iron_ball_strip.png"];
    }
    else if([appDelegate.ballValue isEqualToString:@"golfball"])
    {
        spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"golf_ball_strip.png"];
    }
    else if([appDelegate.ballValue isEqualToString:@"soccerball"])
    {
        spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"soccer_ball_strip.png"];
    }
    else if([appDelegate.ballValue isEqualToString:@"basketball"])
    {
        spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"basket_ball_strip.png"];
    }

    spriteSheet.position = ccp(hole1.position.x,60);
    [self addChild:spriteSheet];

    float frameWidth = 96;
    float frameHeight = 84;

    CCSprite *sprite = [CCSprite spriteWithTexture:spriteSheet.texture rect:CGRectMake(0, 0, frameWidth, frameHeight)];

    [spriteSheet addChild:sprite];

    //if(animation)
    {
        // create the animation
        CCAnimation *spriteAnimation = [CCAnimation animationWithName:@"potting" delay:0.1f];

        int frameCount = 0;
        for (int x = 0; x < 6; x++) 
        {
            // create an animation frame
            CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:spriteSheet.texture rect:CGRectMake(x*frameWidth,0*frameHeight,frameWidth,frameHeight) offset:ccp(0,0)];
            [spriteAnimation addFrame:frame];

            frameCount++;

            // stop looping after we've added 14 frames
            if (frameCount == 6)
            {
                //[self removeChild:spriteSheet cleanup:YES];
                break;
            }
        }

        // create the action
        CCAnimate *spriteAction = [CCAnimate actionWithAnimation:spriteAnimation];
        //CCRepeatForever *repeat = [CCRepeatForever actionWithAction:spriteAction];

        // run the action
        [sprite runAction:spriteAction];
        //[sprite runAction:repeat];
    }
    [self schedule:@selector(loading) interval:0.5];
    [self schedule:@selector(holeFinish) interval:1];
    //[self removeChild:spriteSheet cleanup:YES];
}

Any suggestion will be highly appreciated.

EDIT: What i found is, problem with folling lines [self removeChild:ball1 cleanup:YES];
world->DestroyBody(ballBody);
(MAY be). but as it not occurs always, (as I mentioned), thus it’s being ridiculous.

  • 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-25T10:03:17+00:00Added an answer on May 25, 2026 at 10:03 am

    I think your problem will be that you are trying to delete a body when the b2World is ‘locked’, (When the world is busy working out collisions).

    Try flagging the object as ready for deletion, and deleting it at the start of your next loop:

    Replace:

    [self removeChild:ball1 cleanup:YES];
    world->DestroyBody(ballBody);
    

    with

    ball1.isDead = YES;
    

    And at the start of your next game loop:

    for (Ball b in balls)
    {
        if (b.isDead)
            world->DestroyBody(b.ballBody);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me explain: There are some apps (like the Facebook app) that send emails
Let me explain: I know that, in Java , you can do stuff like
Let me explain the application. Before starting my question, I would like to say
Let me explain this a bit. Imagine I have a table like this: id
let me explain my current situation i have a SharePoint site lets say it
Let me explain. Suppose I want to teach Python to someone who only speaks
Let me explain what I mean : Let's say we have a menu with
First let me explain how I currently handle validation, say, for an IPv4 address:
First let me explain. I have several addresses on the page that I put
Quite new to maven here so let me explain first what I am trying

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.