stop erasing iterator during loop

This commit is contained in:
2025-03-15 14:00:23 -05:00
parent f81c6f98ea
commit b58b071f4c

View File

@@ -38,11 +38,11 @@ void App::run() {
// Main loop // Main loop
while (!done && !modules.empty()) { while (!done && !modules.empty()) {
for(auto m : modules) { for(auto it = modules.begin(); it != modules.end(); it++) {
m->run(); (*it)->run();
} }
for(auto it = toClose.begin(); it != modules.end(); it++) { for(auto it = toClose.begin(); it != toClose.end(); it++) {
unload(it); unload(it);
} }
toClose.clear(); toClose.clear();
@@ -82,22 +82,21 @@ void App::load(std::string lib) {
void App::unload(decltype(Module::self) it) { void App::unload(decltype(Module::self) it) {
void* h = (*it)->getHandle(); void* h = (*it)->getHandle();
std::cout << "retrieved handle\nAttempting to delete module: " << (*it)->getName() << std::endl; std::cout << "retrieved handle\n";
modules.erase((*it)->self);
std::cout << "erased module.self";
std::cout << "Attempting to delete module: " << (*it)->getName() << std::endl;
delete *it; delete *it;
std::cout << "deleted module\n"; std::cout << "deleted module\n";
char* mesg = dlerror();
if(h && !mesg) { dlclose(h);
std::cout << "h: " << h << " attempting to dlclose\n"; std::cout << "successfully dlclosed\n";
dlclose(h);
std::cout << "closed handle\n";
} else {
std::cout << "error: " << mesg << "\n";
}
} }
void App::stopModule(decltype(Module::self) it) { void App::stopModule(decltype(Module::self) it) {
toClose.push_back(*it); toClose.push_back(*it);
modules.erase(it);
} }
void App::handleArgs(const int& argc, char* argv[]) { void App::handleArgs(const int& argc, char* argv[]) {