yohamta / donburi

Just another ECS library for Go/Ebitengine
https://pkg.go.dev/github.com/yohamta/donburi
Other
251 stars 21 forks source link

Panic on event Publishing #102

Closed joelschutz closed 1 year ago

joelschutz commented 1 year ago

If you try to publish an Event that no handler is listening the program panic since no event bus is found.

How to Reproduce

Create a new event and try to publish to it.


type EnemyKilled struct {
    EnemyID int
}

var EnemyKilledEvent = events.NewEventType[*EnemyKilled]()

func TestEvents(t *testing.T) {
    w := donburi.NewWorld()
    EnemyKilledEvent.Publish(w, &EnemyKilled{EnemyID: 1})
}

Problem

It makes sense to only initialize a bus if there is a handler to react to it, but in a game you often need to add or remove subscribers dymanically. Attaching the bus initialization to the Subscribe method makes it difficult since all the system depends on that first subscription.

yohamta commented 1 year ago

Hi @joelschutz , Thank you so much for submitting such a great issue and PR! It has been released as version 1.3.7.