Skip to content

ClosureEvents: listeners of a unit added in init start listening once it is indexed - #503

Draft
Frotty wants to merge 2 commits into
masterfrom
fix/unit-listeners-added-at-init
Draft

Frotty wants to merge 2 commits into
masterfrom
fix/unit-listeners-added-at-init

Conversation

@Frotty

@Frotty Frotty commented Oct 1, 2026

Copy link
Copy Markdown
Member

Fixes #433.

EventListener.add(unit, event) and EventListener.onCast(unit, ability) file a listener under the unit's index. The library indexes the units a map creates in init only after every init block has run (OnUnitEnterLeave dispatches them from a nullTimer), so in init the index is 0. add then warned and dropped the listener, and onCast filed it under slot 0, where the unit's own casts never reached it. Global listeners were not affected, which is why only the unit variants looked broken.

A listener of a unit without an index now waits and is filed, in the order it was added, on the next timer tick, which comes after the indexing. A listener destroyed while it waits is not filed. A unit that still has no index then gets what it got before: the warning for add, slot 0 for casts. Nothing indexes early, so onUnitIndex listeners of packages that initialise later still see every unit.

Checked in the game, with a death listener on two units and a cast listener on a third, all registered in an init block, next to the same registrations made after init and from a nullTimer: before, the three registered in init never ran and the others did; after, all run, each for its own unit only. grill typecheck and grill test (522 of 522) pass.

Not in this PR: a regression test, since it needs control of a map's init block, which the compiletime tests and the in-game suite do not have.

… it is indexed

EventListener.add(unit, event) and onCast(unit, ability) file a listener under the unit's index, and the library indexes the units a map creates in init only after every init block has run. In init the index is 0, so add warned and dropped the listener and onCast filed it under slot 0, where the unit's casts never reached it.

A listener of a unit without an index now waits and is filed, in the order it was added, on the next timer tick, which comes after the indexing. One destroyed while it waits is not filed. A unit that still has no index then gets what it got before: the warning for add, slot 0 for casts.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T17:28:32.247871Z b00e8af Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ebed43f46

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread wurst/closures/ClosureEvents.wurst
Comment thread wurst/closures/ClosureEvents.wurst Outdated
…iting for it

unregisterEventsForUnit cleared the lists a unit's listeners are filed in, and a listener that was still waiting for the unit's index was filed afterwards, so it could fire after the cleanup. It now destroys the waiting ones as well. A waiting listener has a flag of its own instead of being told by its unit not being null, and a null unit is not queued at all, as it can never get an index.
@Frotty

Frotty commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: b00e8afdb3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty
Frotty marked this pull request as draft October 1, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EventListener.add(u, EVENT_PLAYER_UNIT_SELECTED) does not work in init block?

1 participant