-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArrayIndexOutOfBoundsException #159
Comments
If I remove the FamilyOnAdd interface, the error does not occur. Die world.kt datei private fun updateAggregatedFamilyHooks(family: Family) {
// system validation like in initAggregatedFamilyHooks is not necessary
// because it is already validated before (in initAggregatedFamilyHooks and in add/remove system)
// update family add hook by adding systems' onAddEntity calls after its original world cfg hook
val addSystems = systems.filter { it is IteratingSystem && it is FamilyOnAdd && it.family == family }
val ownAddHook = worldCfgFamilyAddHooks[family] // it crashed here
family.addHook = if (ownAddHook != null) { entity ->
ownAddHook(this, entity)
addSystems.forEach { (it as FamilyOnAdd).onAddEntity(entity) }
} else { entity ->
addSystems.forEach { (it as FamilyOnAdd).onAddEntity(entity) }
} |
Can you provide a simple example on how to reproduce it? In general: it is not a good practice to link systems together. I see you reference a TreasureSystem and a TileMapPathFinderSystem in your EnemyWayWalkerSystem. That is not a good design. Systems should be separate and ideally don't know from each other. One solution would be to trigger events and a system reacts on that and does its thing. Another solution is to add components/remove components to an entity to trigger a specific other system. Second: You are modifying the entity configuration within a family add hook (=onAddEntity). I don't know if that works and that might be the problem with the ArrayIndexOutOfBounds, but I am not 100% sure. Anyway, to track down the issue, please provide a simplified example where that happens. But maybe it solves itself already when you redesign your approach a little bit, keeping the best practices in my mind that I mentioned above. |
OMG, class AnComponent : Component<AnComponent> {
override fun type() = AnComponent
companion object : ComponentType<AnComponent>()
}
class StartSystem : IteratingSystem(family = family {
all(AnComponent)
}) {
override fun onTickEntity(entity: Entity) {}
}
class AddLaterSystem(world: World, tag: EntityTag) : IteratingSystem(world = world, family = world.family {
all(tag)
}), FamilyOnAdd {
override fun onInit() {}
override fun onTickEntity(entity: Entity) {}
override fun onAddEntity(entity: Entity) {}
}
fun main() {
val world = configureWorld {
systems {
add(StartSystem())
}
}
for (i in 0 until 62) {
val entityTag = object : EntityTag() {}
world.family { all(entityTag) }
}
val entityTag = object : EntityTag() {} // crash happens if the ID is EXACTLY 63!!!
println("entityTagID: ${entityTag.id}")
val addLaterSystem = AddLaterSystem(world, entityTag)
println("family: ${addLaterSystem.family}")
world.add(addLaterSystem) // crash here
} Output:
|
Nice, thank you! Seems like an issue if someone has more than 64 components. That requires a second long in the BitArray class which seems to crash the hashcode function of it. I try to have a look on the weekend. |
Yes, you're right, this is the short version of the Crash: val bitArray = BitArray(1)
bitArray.set(63)
println(bitArray.hashCode()) // crash |
It is quite interesting because I think I just use LibGDX Bits hashCode from https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils/Bits.java Either that is already broken, which I doubt, or I did a mistake somewhere in the class. But now that we know the issue thanks to you, I think it should not be too difficult to solve it . |
Is the problem solved? 🙂 |
stackTrace:
The System:
The text was updated successfully, but these errors were encountered: