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

  • Home
  • SEARCH
  • 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 4531662
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:55:56+00:00 2026-05-21T13:55:56+00:00

I have the following code: for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())

  • 0

I have the following code:

for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{
    if (b->GetUserData() != NULL) 
    {               
        CCSprite *itemSprite = (CCSprite*)b->GetUserData();
        CGSize SpriteSize;
        SpriteSize.height = itemSprite.contentSize.height;
        SpriteSize.width = itemSprite.contentSize.width;
        CGPoint SpritePosition=[itemSprite position];           
    }
}

Just get the position of sprite, but this program crash sometimes in:

SpriteSize.height = itemSprite.contentSize.height;

and this line:

CGPoint SpritePosition=[itemSprite position];

I am using cocos2d .99.5.

Edit: here is my crash log:

Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000f
Crashed Thread: 0

Thread 0 Crashed:
0   libobjc.A.dylib                 0x00002666 objc_msgSend_stret + 14
1   ShootTheMonkey                  0x0004c066 -[LevelFour ccTouchBegan:withEvent:] (LevelFour.mm:1432)
2   ShootTheMonkey                  0x00321bf0 -[CCTouchDispatcher touches:withEvent:withTouchType:] (CCTouchDispatcher.m:238)
3   ShootTheMonkey                  0x00322454 -[CCTouchDispatcher touchesBegan:withEvent:] (CCTouchDispatcher.m:305)
4   ShootTheMonkey                  0x003240ec -[EAGLView touchesBegan:withEvent:] (EAGLView.m:318)
5   UIKit                           0x00053d72 -[UIWindow _sendTouchesForEvent:] + 254
6   UIKit                           0x000536fe -[UIWindow sendEvent:] + 74
7   UIKit                           0x0004f320 -[UIApplication sendEvent:] + 260
8   UIKit                           0x0004ec8c _UIApplicationHandleEvent + 4772
9   GraphicsServices                0x00003b2c PurpleEventCallback + 660
10  CoreFoundation                  0x00022d96 CFRunLoopRunSpecific + 2214
11  CoreFoundation                  0x000224da CFRunLoopRunInMode + 42
12  GraphicsServices                0x000030d4 GSEventRunModal + 108
13  GraphicsServices                0x00003180 GSEventRun + 56
14  UIKit                           0x0000342a -[UIApplication _run] + 374
15  UIKit                           0x00001954 UIApplicationMain + 636
16  ShootTheMonkey                  0x0000377e main (main.m:13)
17  ShootTheMonkey                  0x0000373c start + 32
  • 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-21T13:55:56+00:00Added an answer on May 21, 2026 at 1:55 pm

    Since you do not post the crash dump or stack trace, I can only guess. AFAIK there are at least two reasons:

    1. You assign objects of multiple classes to body->SetUserData(). The crash happens when you cast the user data to CCSprite when it’s in fact not a CCSprite. Although I doubt this is the case since usually people assign objects of the same class to it.

    2. The second reason is more likely to happen due to the way people usually depend on CCLayer to retain its CCSprite children (rather than explicitly retaining them). When you remove the CCSprites from the parent CCLayer, the latter releases the former and if retain count == 0 (very likely) the CCSprites are released from the heap. But remember that some of b2Bodies are still holding the pointers to these CCSprites through the user data attributes? So what happen when you iterate over all the bodies and try to use the released CCSprites that are still attached to the user data? Crash!

    The way to fix this is that you need to remove the bodies when their corresponding sprites are removed from their CCLayer, by either subclassing CCSprite to add an ivar that points to b2Body, or by wrapping both objects (i.e sprite and body) in another class. Then add code to remove the body when the sprite is about to be de-alloc-ed.

    Hope this helps. If not, please post more details (crash dump or stack trace).

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

Sidebar

Related Questions

I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with
I have the following code in a web.config file of the default IIS site.
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
I have the following code snippet. $items['A'] = Test; $items['B'] = Test; $items['C'] =
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
I have the following code: String inputFile = somefile.txt; FileInputStream in = new FileInputStream(inputFile);
I have the following code: ListBox.DataSource = DataSet.Tables(table_name).Select(some_criteria = match) ListBox.DisplayMember = name The
I have the following code making a GET request on a URL: $('#searchButton').click(function() {

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.