hello
i'm creating a simple gui system for games (as it's just for learning purposes, i'd like to create it from scratch).
but I can't find where this pure virtual function is being called from. I know i'ts about 100 lines of code, but this is the minimal example that I could get that reproduces the problem:
The problem is that GuiManager::run() is calling run() on each of the TextButtons, which is equivalent to activating the buttons. The actions for all the buttons involve calling MenuHandler::changeMenu(), which calls GuiManager::removeAll(), which clears GuiManager::m_text_buttons.
In other words, you're modifying an std::vector as you traverse it.
This would fix the crash, although I doubt it's what you intended:
1 2 3
auto v = std::move(m_text_buttons);
for (auto &n : v)
n.run();
You'll probably want a display() function or something.
this is the minimal example that I could get that reproduces the problem
This program contains multiple layers of trivial passthrough functions and purposeless class types.
There is some abstract class hierarchy being managed by a manager which is handled by some handler but the program just calls some functions in a list.
If the program was written to solve the problem directly, it would be more obvious that it modifies the list of functions while iterating over it.