Skip to content

Callback fixes and allow re.on_* callbacks to remove itself#1503

Open
hcdd0304 wants to merge 4 commits intopraydog:masterfrom
hcdd0304:callback_fixes_and_allow_remove
Open

Callback fixes and allow re.on_* callbacks to remove itself#1503
hcdd0304 wants to merge 4 commits intopraydog:masterfrom
hcdd0304:callback_fixes_and_allow_remove

Conversation

@hcdd0304
Copy link
Copy Markdown
Contributor

@hcdd0304 hcdd0304 commented Jan 16, 2026

Fixes

  • Calling re.on_frame while another re.on_frame is executing will cause crashes (sometimes). Reason being callback vector being reallocated/resized while being iterated
  • Write a custom class for storing callback to reduce duplication
re.on_frame(function()
   if (...) then
      re.on_frame()
   end
end)

(Note (I edit): the exception is caught by lua protected call though, I can view it only when attaching Visual Studio debugger with the game)

Addition

  • Add a way for re.on_* callback to opt itself out. Requested by modder ridog for their MHWilds mod

Test code:

local current_count = 0
local stop_at = 10

re.on_frame(function()
    log.info("Frame update count: " .. current_count)
    current_count = current_count + 1

    if current_count >= stop_at then
        log.info("Reached the stop count of " .. stop_at .. ". Stopping updates.")
        return re.CallbackNextAction.STOP
    end
end)
image

on_frame is added while the on_frame callback array is executed. Corrupt, quicker death for the game

This makes death slower. Not the root cause
return CallbackNextAction.STOP inside on_frame to stop it from running again
@hcdd0304 hcdd0304 changed the title Callback fixes and allow remove Callback fixes and allow re.on_* callbacks to remove itself Jan 16, 2026
@hcdd0304 hcdd0304 marked this pull request as ready for review January 16, 2026 05:26
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.

1 participant