App crashes every second time

  ... discussions about development with the GLES2 branch of AndEngine.

App crashes every second time

Postby wakeUpCall » Tue Jun 05, 2012 6:50 pm

Hi, my activity always crashes the second time I open my app.
that's what the catlog says:

06-05 18:47:29.209: E/AndroidRuntime(6835): FATAL EXCEPTION: UpdateThread
06-05 18:47:29.209: E/AndroidRuntime(6835): java.lang.IllegalStateException: pEntity '' already has a parent: 'GameScene'. New parent: 'GameScene'!
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.entity.Entity.assertEntityHasNoParent(Entity.java:1412)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.entity.Entity.attachChild(Entity.java:724)
06-05 18:47:29.209: E/AndroidRuntime(6835): at com.go.work.LevelBuilder.attachToScene(LevelBuilder.java:82)
06-05 18:47:29.209: E/AndroidRuntime(6835): at com.go.work.LevelBuilder.build(LevelBuilder.java:53)
06-05 18:47:29.209: E/AndroidRuntime(6835): at com.go.work.GameScene.<init>(GameScene.java:38)
06-05 18:47:29.209: E/AndroidRuntime(6835): at com.go.work.LevelMenuScene.onSceneTouchEvent(LevelMenuScene.java:35)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.entity.scene.Scene.onSceneTouchEvent(Scene.java:388)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.engine.Engine.onTouchScene(Engine.java:452)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.engine.Engine.onTouchEvent(Engine.java:438)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.input.touch.controller.BaseTouchController$TouchEventRunnablePoolItem.run(BaseTouchController.java:102)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.util.adt.pool.RunnablePoolUpdateHandler.onHandlePoolItem(RunnablePoolUpdateHandler.java:54)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.util.adt.pool.RunnablePoolUpdateHandler.onHandlePoolItem(RunnablePoolUpdateHandler.java:1)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.util.adt.pool.PoolUpdateHandler.onUpdate(PoolUpdateHandler.java:88)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.input.touch.controller.BaseTouchController.onUpdate(BaseTouchController.java:62)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.engine.Engine.onUpdate(Engine.java:584)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.engine.Engine.onTickUpdate(Engine.java:548)
06-05 18:47:29.209: E/AndroidRuntime(6835): at org.andengine.engine.Engine$UpdateThread.run(Engine.java:820)

I don't attach anything twice to my GameScene. And as said it just happens every 2nd time.

Every help is appriciated.
wakeUpCall
 
Posts: 8
Joined: Sun May 27, 2012 4:08 pm

Re: App crashes every second time

Postby OzLark » Wed Jun 06, 2012 5:18 am

That looks to me like your app hasn't closed off completely - do you need to handle thing differently in onPause() onResume() etc?
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: App crashes every second time

Postby wakeUpCall » Wed Jun 06, 2012 2:44 pm

Not yet.
Actually I don't handle anything with onResume() and onPause().
wakeUpCall
 
Posts: 8
Joined: Sun May 27, 2012 4:08 pm

Re: App crashes every second time

Postby nazgee » Wed Jun 06, 2012 4:12 pm

I am *guessing* that you are using some static shi# :)
You probably add entities to a static object that keeps living when you "quit" our app. Then you "run" your app again, and reunite with your statics. You once again feed it with entities- and you get the error :)

I do not like statics. If you like 'em: ou'll have to get used to debugging stuff like that and sth harder ;]
Dirt Rider Mayhem is PUBLISHED now!
Image
User avatar
nazgee
 
Posts: 524
Joined: Fri Oct 21, 2011 10:31 pm
Location: Poland, Wrocław

Re: App crashes every second time

Postby fatal » Thu Jun 07, 2012 2:47 am

You are attaching stuff in touch event every time, that's why you get the error. You should attach your entity(ies) only 1 time, else you get this error.

nazgee: Static objects are destroyed when the app closing (not onpause, ondestroy). There aren't any problem with statics if you are using them correctly. I prefer static for textureatlases and textureregions cause why am i should load the texture to the memory every time i'm creating the same sprite with the same texture?:)
User avatar
fatal
 
Posts: 469
Joined: Sun Jan 08, 2012 2:20 am
Location: Budapest, Hungary

Re: App crashes every second time

Postby wakeUpCall » Thu Jun 07, 2012 7:30 pm

Ok thanks.
My problem is that I designed my game to access my main Activity by a static way and it would be a shit load of work to change this.
So what could I do?
wakeUpCall
 
Posts: 8
Joined: Sun May 27, 2012 4:08 pm

Re: App crashes every second time

Postby fatal » Thu Jun 07, 2012 7:49 pm

wakeUpCall wrote:Ok thanks.
My problem is that I designed my game to access my main Activity by a static way and it would be a shit load of work to change this.
So what could I do?


And what's the problem with it? I don't understand. I'm attaching stuff in onCreateResources / onPopulateScene.
User avatar
fatal
 
Posts: 469
Joined: Sun Jan 08, 2012 2:20 am
Location: Budapest, Hungary


Return to GLES2

Who is online

Users browsing this forum: AdaMoOo, Alexa [Bot], Google [Bot], iSegal, marco250677, Navil and 38 guests