Skip to content

Fix: reopen sell-confirm GUI on player region thread (Folia/Canvas crash)#248

Merged
ptthanh02 merged 1 commit into
NighterDevelopment:mainfrom
Potenza7:fix/folia-sell-confirm-reopen-thread
May 30, 2026
Merged

Fix: reopen sell-confirm GUI on player region thread (Folia/Canvas crash)#248
ptthanh02 merged 1 commit into
NighterDevelopment:mainfrom
Potenza7:fix/folia-sell-confirm-reopen-thread

Conversation

@Potenza7
Copy link
Copy Markdown
Contributor

Problem

On Folia/Canvas, confirming a spawner sell crashes when the previous GUI is reopened:

Thread failed main thread check: Cannot init menu async
  at net.minecraft.server.level.ServerPlayer.initMenu
  at ...SpawnerSellConfirmListener.reopenPreviousGui(SpawnerSellConfirmListener.java:197)
  at ...SpawnerSellConfirmListener.lambda$handleConfirm$1(SpawnerSellConfirmListener.java:174)
  at ...Scheduler.lambda$runTask$0 ... FoliaGlobalRegionScheduler

Cause

In handleConfirm(), the post-sell onComplete reopens the GUI via Scheduler.runTask (the global region scheduler). But player.openInventory()ServerPlayer.initMenu() must run on the player's own region thread, so Folia/Canvas fails the TickThread check.

Fix

Dispatch the reopen via Scheduler.runEntityTask(player, ...) instead, so it runs on the player's region thread.

  • Paper: falls back to the main thread (unchanged behavior).
  • If the player logged off mid-sell, the entity task simply never runs (safe).

One-line change in SpawnerSellConfirmListener#handleConfirm (plus comment updates).

Tested on Canvas 26.1.2 — crash gone, GUI reopens correctly after selling.

…vas)

After a spawner sell completes, reopenPreviousGui() was dispatched via the
global region scheduler (Scheduler.runTask). player.openInventory() ->
ServerPlayer.initMenu() must run on the player's own region thread, so on
Folia/Canvas this throws "Cannot init menu async" (TickThread check fail).

Use Scheduler.runEntityTask(player, ...) so the GUI reopens on the player's
region thread. On Paper this falls back to the main thread; if the player
logged off mid-sell the entity task simply never runs.
@Potenza7 Potenza7 force-pushed the fix/folia-sell-confirm-reopen-thread branch from fa603ab to f9e9b8f Compare May 29, 2026 09:10
@Dueris
Copy link
Copy Markdown

Dueris commented May 29, 2026

I can confirm(Canvas dev) as someone who's worked with Folia for a long time, all things that involve an entity instance should be scheduled to the entity in question. The global tick should never be used for that, as it's used for states that are global and doesn't have a specified location. Think time/weather for example.

If there are other places in the codebase improperly doing this, it'd be recommended to fix that, otherwise it can cause a lot of issues that are often, frankly, undiagnosable.

@ptthanh02 ptthanh02 merged commit f48aaff into NighterDevelopment:main May 30, 2026
1 check passed
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.

3 participants