Slick Forums

Hard Freeze During GroupManager.Add
Page 1 of 1

Author:  Jo [ Sat May 10, 2014 8:08 pm ]
Post subject:  Hard Freeze During GroupManager.Add

I've been fiddling with Artemis vanilla for a while in a libgdx project. I've encountered the following problem when I spawn a new Entity during a process event.

The stack trace is
Thread [LWJGL Application] (Suspended)   
   Object.hashCode() line: not available [native method]   
   HashMap<K,V>.hash(Object) line: not available   
   HashMap<K,V>.getEntry(Object) line: not available   
   HashMap<K,V>.get(Object) line: not available   
   GroupManager.add(Entity, String) line: 49   
   EntityFactory.spawnInfected(int, int) line: 80   
   InfectedAISystem$1.handleSight(Entity, Entity) line: 50   
   InfectedAISystem$VisiblePair.checkForVisibility() line: 130   
   InfectedAISystem.processEntities(ImmutableBag<Entity>) line: 98   
   InfectedAISystem(EntitySystem).process() line: 57   
   World.process() line: 354   
   Play.update(float) line: 98   
   GameStateManager.update(float) line: 44   
   Game.render() line: 58   
   LwjglApplication.mainLoop() line: 206   
   LwjglApplication$ line: 114   

The line which causes this code is `EntityFactory.worldReference.getManager(GroupManager.class).add(e, INFECTED);`.

WorldReference is already initialized. GroupManager is valid. I broke down the line a little further and found the lock seems to happen in the .add call.

As near as I can tell, the program is running indefinitely without doing a hard crash, as I've often seen before. It just runs forever without so much as the terminate program dialog popping up. When I figure out how to bind the source.jar to this project, I can dig deeper, but in the meanwhile I feel like the issue might have something to do with the modification happening during a process() event. Has anyone experienced this before?

Author:  junkdog [ Sun May 11, 2014 2:11 pm ]
Post subject:  Re: Hard Freeze During GroupManager.Add

Are you by any chance running artemis in a multithreaded environment? It appears to be a thread issue, alternatively entity has a faulty hashcode implementation (only if you've extended Entity).

I seem to remember that there used to be some problem with GroupManager in the past, but I might be mistaken. Regardless, you shouldn't run vanilla artemis - it has too many bugs that were never fixed. There are several forks that fix all bugs present in vanilla. Gdx-artemis and mine (artemis-odb) fix these; there are other forks too, but I'm not sure to what degree they remedy the bugs.

Author:  Jo [ Sun May 11, 2014 5:04 pm ]
Post subject:  Re: Hard Freeze During GroupManager.Add

It looks like it is a threading issue. I can resolve it by pooling the group adds and entity spawns until the end of the world processing function. I have not overridden or extended entity.

I think I might have taken a look at your implementation a while back, but didn't use it since I wasn't sure how to use the Maven repository with gradle, but I'll pull a jar and try again. Should be a drop-in replacement, ja?

Author:  junkdog [ Sun May 11, 2014 5:26 pm ]
Post subject:  Re: Hard Freeze During GroupManager.Add

Do you run multiple threads in your game? Artemis is single threaded, so when dealing with multiple threads you need to synchronize, or better compartmentalize, access to artemis - if that is the case.

Vanilla artemis was a little flaky when it came to creating entities during an ongoing process loop. Sounds like it might be what's causing it, though I don't remember seeing your particular problem. Worth a short anyway.

The Underkeep and Naturually Selected 2d both use gradle - they're linked from the readme too.

Edit: artemis-odb should be fully API-compatible with vanilla (up until when/if artemis-odb 1.0.0 is released - but I'd rather avoid breaking compatibility).

Author:  Jo [ Mon May 12, 2014 3:53 am ]
Post subject:  Re: Hard Freeze During GroupManager.Add

Yeah, it looks like it was a threading issue.

For anyone who happens to be reading this thread in the future (or is searching for "artemis entity system gradle libgdx") or is looking for a way to add artemis-odb to the new libgdx with gradle, edit build.gradle and add the following to the project core dependencies:

        compile fileTree(dir: 'libs', include: '*.jar')
        compile group: 'net.onedaybeard.artemis', name: 'artemis-odb', version: '0.5.0'

EDIT: By the way, the fork made a fine drop-in replacement, junkdog. Thanks.

Author:  junkdog [ Mon May 12, 2014 8:21 am ]
Post subject:  Re: Hard Freeze During GroupManager.Add

You don't need to grab it from maven repo directly; I'm not familiar with gradle but it looks like you've placed the artemis jars inside 'libs/'?

Version 0.6.0 is just around the corner btw; only thing remaining is writing some documentation - I don't expect any more commits before release. The snapshot url is: ... -SNAPSHOT/

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group