stop erasing iterator during loop
This commit is contained in:
25
src/App.cpp
25
src/App.cpp
@@ -38,11 +38,11 @@ void App::run() {
|
||||
// Main loop
|
||||
while (!done && !modules.empty()) {
|
||||
|
||||
for(auto m : modules) {
|
||||
m->run();
|
||||
for(auto it = modules.begin(); it != modules.end(); it++) {
|
||||
(*it)->run();
|
||||
}
|
||||
|
||||
for(auto it = toClose.begin(); it != modules.end(); it++) {
|
||||
for(auto it = toClose.begin(); it != toClose.end(); it++) {
|
||||
unload(it);
|
||||
}
|
||||
toClose.clear();
|
||||
@@ -82,22 +82,21 @@ void App::load(std::string lib) {
|
||||
|
||||
void App::unload(decltype(Module::self) it) {
|
||||
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;
|
||||
std::cout << "deleted module\n";
|
||||
char* mesg = dlerror();
|
||||
if(h && !mesg) {
|
||||
std::cout << "h: " << h << " attempting to dlclose\n";
|
||||
dlclose(h);
|
||||
std::cout << "closed handle\n";
|
||||
} else {
|
||||
std::cout << "error: " << mesg << "\n";
|
||||
}
|
||||
|
||||
dlclose(h);
|
||||
std::cout << "successfully dlclosed\n";
|
||||
}
|
||||
|
||||
void App::stopModule(decltype(Module::self) it) {
|
||||
toClose.push_back(*it);
|
||||
modules.erase(it);
|
||||
}
|
||||
|
||||
void App::handleArgs(const int& argc, char* argv[]) {
|
||||
|
||||
Reference in New Issue
Block a user