WerWolv / libtesla

The support library for Tesla overlays
GNU General Public License v2.0
218 stars 49 forks source link

Fix crash when change gui from handleInput #12

Closed diwo closed 4 years ago

diwo commented 4 years ago

If onClick in handleInput calls changeTo to put new gui onto m_guiStack, the vector may resize and cause the currentGui reference to no longer be valid, causing a crash.

WerWolv commented 4 years ago

Hm. It might be better to just use a fixed size array then instead of a vector. Your fix is just a workaround the real issue kinda...

diwo commented 4 years ago

Some kind of linked list would be better, since the vector is used as a stack anyway. I can't get a clear answer on whether std::deque reallocates or not, let me look into this.

I'll put gui's handleInput back so that it's fired regardless of whether it's been handled by an element. It's needed to implement drag-and-release detection without being interrupted. If there's a need to bypass gui's handleInput when it's already handled by an element, the handled flag could be passed to gui's handleInput as an arg.

diwo commented 4 years ago

Changed gui stack implementation from vector to stack backed by linked list. Kept gui->handleInput behavior the same as before.

Summary on reference invalidation for various containers here: https://stackoverflow.com/a/54004916/983429