Skip to content

Conversation

@MohabCodeX
Copy link
Contributor

Problem

When events trigger other events (nested), the parent event would lose its cancellation reason and context.

Solution

Replaced single event context pointer with a proper context stack, each event now maintains its own cancellation state and reason.

Results

Before

[08:30:50] [debug] [testing]\vbug\server.lua:28 - Testing nested events...
[08:30:50] [debug] [testing]\vbug\server.lua:21 - PASS: Event B has its reason
[08:30:50] [debug] [testing]\vbug\server.lua:12 - FAIL: Expected 'Reason A', got ''

After

[08:30:50] [debug] [testing]\vbug\server.lua:28 - Testing nested events...
[08:30:50] [debug] [testing]\vbug\server.lua:21 - PASS: Event B has its reason
[08:30:50] [debug] [testing]\vbug\server.lua:12 - PASS: Event A kept its reason

Testing script
addEvent("eventA", true)
addEvent("eventB", true)

addEventHandler("eventA", root, function()
    cancelEvent(true, "Reason A")
    triggerEvent("eventB", root)
    
    local reason = getCancelReason()
    if reason == "Reason A" then
        outputDebugString("PASS: Event A kept its reason")
    else
        outputDebugString("FAIL: Expected 'Reason A', got '" .. reason .. "'")
    end
end)

addEventHandler("eventB", root, function()
    cancelEvent(true, "Reason B")
    
    local reason = getCancelReason()
    if reason == "Reason B" then
        outputDebugString("PASS: Event B has its reason")
    else
        outputDebugString("FAIL: Expected 'Reason B', got '" .. reason .. "'")
    end
end)

addCommandHandler("testevent", function()
    outputDebugString("Testing nested events...")
    triggerEvent("eventA", root)
end)

@MohabCodeX MohabCodeX marked this pull request as draft November 9, 2025 07:50
@MohabCodeX MohabCodeX marked this pull request as ready for review November 10, 2025 00:14
@FileEX FileEX added the bugfix Solution to a bug of any kind label Nov 14, 2025
@FileEX FileEX merged commit 8d41e19 into multitheftauto:master Nov 22, 2025
MTABot pushed a commit that referenced this pull request Nov 22, 2025
7ebcf59 Simplify ACL request refresh detection (improves #4409) (#4483)
8d41e19 Resolve Event Context Loss in Nested Event Cacnellation (#4529)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Solution to a bug of any kind

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants