TOOL_EVENT: fix lifetime issues with const aEvent& refs

Without this the event is on the stack, and as soon as the tool calls
Wait(), the event will be deallocated. The aEvent reference will then
point to invalid memory.
This commit is contained in:
Mike Williams 2022-09-15 10:20:27 -04:00
parent 45d6b4a9fc
commit b7ba24b2d9
1 changed files with 7 additions and 1 deletions

View File

@ -64,6 +64,7 @@ struct TOOL_MANAGER::TOOL_STATE
contextMenu = aState.contextMenu; contextMenu = aState.contextMenu;
contextMenuTrigger = aState.contextMenuTrigger; contextMenuTrigger = aState.contextMenuTrigger;
cofunc = aState.cofunc; cofunc = aState.cofunc;
initialEvent = aState.initialEvent;
wakeupEvent = aState.wakeupEvent; wakeupEvent = aState.wakeupEvent;
waitEvents = aState.waitEvents; waitEvents = aState.waitEvents;
transitions = aState.transitions; transitions = aState.transitions;
@ -102,6 +103,9 @@ struct TOOL_MANAGER::TOOL_STATE
/// Tool execution context /// Tool execution context
COROUTINE<int, const TOOL_EVENT&>* cofunc; COROUTINE<int, const TOOL_EVENT&>* cofunc;
/// The first event that triggered activation of the tool.
TOOL_EVENT initialEvent;
/// The event that triggered the execution/wakeup of the tool after Wait() call /// The event that triggered the execution/wakeup of the tool after Wait() call
TOOL_EVENT wakeupEvent; TOOL_EVENT wakeupEvent;
@ -125,6 +129,7 @@ struct TOOL_MANAGER::TOOL_STATE
contextMenu = aState.contextMenu; contextMenu = aState.contextMenu;
contextMenuTrigger = aState.contextMenuTrigger; contextMenuTrigger = aState.contextMenuTrigger;
cofunc = aState.cofunc; cofunc = aState.cofunc;
initialEvent = aState.initialEvent;
wakeupEvent = aState.wakeupEvent; wakeupEvent = aState.wakeupEvent;
waitEvents = aState.waitEvents; waitEvents = aState.waitEvents;
transitions = aState.transitions; transitions = aState.transitions;
@ -781,7 +786,8 @@ bool TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent )
// got match? Run the handler. // got match? Run the handler.
setActiveState( st ); setActiveState( st );
st->idle = false; st->idle = false;
st->cofunc->Call( aEvent ); st->initialEvent = aEvent;
st->cofunc->Call( st->initialEvent );
handled = true; handled = true;
if( !st->cofunc->Running() ) if( !st->cofunc->Running() )