junkdog / artemis-odb

A continuation of the popular Artemis ECS framework
BSD 2-Clause "Simplified" License
769 stars 109 forks source link

[BUG] Randomly get MundaneWireException while doing injection #650

Open cypai opened 2 years ago

cypai commented 2 years ago

I seem to be getting MundaneWireException randomly while injecting a custom class. The stack trace:

Caused by: com.artemis.MundaneWireException: Error while wiring com.pipai.dragontiles.artemis.systems.animation.AdjustHandAnimation
        at com.artemis.injection.CachedInjector.inject(CachedInjector.java:80)
        at com.artemis.World.inject(World.java:136)
        at com.artemis.World.inject(World.java:109)
        at com.pipai.dragontiles.artemis.systems.animation.Animation.init(Animation.kt:15)
        at com.pipai.dragontiles.artemis.systems.animation.CombatAnimationSystem.queueAnimation(CombatAnimationSystem.kt:38)
        at com.pipai.dragontiles.artemis.systems.animation.CombatAnimationSystem.adjustHand(CombatAnimationSystem.kt:84)
        at com.pipai.dragontiles.artemis.systems.animation.CombatAnimationSystem.handleHandAdjustedEvent(CombatAnimationSystem.kt:80)
        ... 19 more
Caused by: com.artemis.MundaneWireException: Failed to inject com.artemis.ComponentMapper into com.pipai.dragontiles.artemis.systems.animation.AdjustHandAnimation: ComponentMapper not registered with world.
        at com.artemis.injection.CachedInjector.onFailedInjection(CachedInjector.java:179)
        at com.artemis.injection.CachedInjector.injectField(CachedInjector.java:165)
        at com.artemis.injection.CachedInjector.injectValidFields(CachedInjector.java:90)
        at com.artemis.injection.CachedInjector.inject(CachedInjector.java:75)
        ... 25 more

The offending code (truncated a bit):

abstract class Animation {
    protected lateinit var world: World

    fun init(world: World) {
        this.world = world
        world.inject(this)
    }
}