zllangct / ecs

A Go-implementation of the ECS (Entity-Component-System), focus on the development of game server.
BSD 3-Clause "New" or "Revised" License
132 stars 10 forks source link

Add Entity, Destroy Entity, Add another Entity throws error #15

Closed cchandel closed 2 years ago

cchandel commented 2 years ago

Hi, I'm adding a weapon entity game.World.NewEntity().Add(p, m, t, r) then deleting it after its run ecs.EntityDestroy(w.World(), data.M.Owner().Entity())

When I want to re-add another weapon entity game.World.NewEntity().Add(p, m, t, r)

I get an error


panic: runtime error: index out of range [9] with length 9

goroutine 44 [running]:
github.com/zllangct/ecs.(*Collection[...]).Add(0xc000688280, 0xc0000b7000)
        /home/chaitanya/workspace/astt/ecs/collection.go:43 +0x2a9
github.com/zllangct/ecs.(*Component[...]).addToCollection(0x20?, {0xd14ee0?, 0xc000688280?})
        /home/chaitanya/workspace/astt/ecs/component.go:145 +0x3f
github.com/zllangct/ecs.(*ComponentCollection).getTempTasks.func1()
        /home/chaitanya/workspace/astt/ecs/component_collection.go:179 +0x286
github.com/zllangct/ecs.(*systemFlow).run.func4()
        /home/chaitanya/workspace/astt/ecs/system_flow.go:197 +0x42
github.com/zllangct/ecs.(*Worker).Start.func1()
        /home/chaitanya/workspace/astt/ecs/goroutine_pool.go:28 +0x39
created by github.com/zllangct/ecs.(*Worker).Start
        /home/chaitanya/workspace/astt/ecs/goroutine_pool.go:16 +0x56
panic: runtime error: index out of range [9] with length 9```

  Am I doing something wrong ?

Thanks
zllangct commented 2 years ago

thanks for reporting, this bug fixed now