Anyone had any trouble with setPosition?

Very short and simple, I switch to my new scene and there I have MenuItemImage and Menu. It workds perfectly. My menu item is added to the layer and no problem.
Only when I try to just simply setPosition my Menu item, the whole thing crashes. Means I get bad access when my new scene tries to load up. SIGABRT!

backButtonMenu->setPosition(ccp(10, 10));

in what world a line of code like that would cause the layer which itself is in it, not to even load!

please help
thanks in advance.

Are you sure that ‘backButtonMenu’ points to a valid location? Could you show some more code?

BTW : simpler liner can cause more trouble :slight_smile:

sure,

backButton = CCMenuItemImage::create(“Icon.png”, “Icon.png”, this, menu_selector(StartGame::Back));
backButtonMenu = CCMenu::create(backButton,NULL);
//backButtonMenu~~>setPosition);
this~~>addChild(backButtonMenu);

see that code above workds, the button appears in the center and as I have written in StartGame::Back() function it does goto the main menu.

things fall apart when I “remove” the comment above and let backButtonMenu->setPosition(ccp(10, 10)); run too.

all these are in init function of my layer class.

Let me sum it up in a single sentence:

I cant set the position of my Menu item in my layer (CCLayer class), only that. Default position works, but I cant set it, on my screen.

If i tried to do so, the whole layer wont load.

im using the latest version of cocos2dx.

Well, that is one strange thing :slight_smile:

What system are you on? What platform are you targeting? Could you please show the whole init() function and the *.h file of your class?

Im trying to add multiple files but it doesnt work,
if it didnt work ill upload them one by one

Im using mac osx lion, xcode 4.6.3 iphone simulator 6.1 and my target device will be universal.

I changed some .mm files content to landscape my view and it worked, cant think if it has anything to do with my current problem.

2nd file

3rd one

and 4th

just dont worry about the Arena class its a very simple class which for now puts a background in my layer and it works, before those menu items came to the picture :slight_smile:

Well, everything looks ok… Have you tried the usual voodoo - clean the project and remove it from simulator (same way as you would uninstall an app from device) ?

Yes I did that several times, and the funny thing is even without the setPosition, “sometimes” the back and forth process crashes :slight_smile:
this really is driving me crazy, what is causing it to crash sometimes!?
I also added a destructor to my Arena class, but no change.
but it will always crash when i use setPosition.
Either im in a bad dream, or cocos2dx has some serious issues :frowning:

Ok, it is a bad dream and here’s why,

this line doesnt work:

backButtonMenu~~>setPosition);
BUT, this line works:
backButtonMenu~~>setPosition(ccp(size.width-1,size.height-1));

seems like atleast “half” of the menu item should be “inside” the screen maybe? that explains why ccp(10,10) didnt work. because the dimensions of the menu item (precisely its image) divided by 2 are greater than 10. meaning height and width themselves are greater than 20! resulting it to be out the screen by more than half of it, in the bottom left corner when positioned to ccp(10,10).
Thanks for looking into it though I appreciate it. it took about 4 hours of mine.