stop erasing iterator during loop
This commit is contained in:
23
src/App.cpp
23
src/App.cpp
@@ -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) {
|
|
||||||
std::cout << "h: " << h << " attempting to dlclose\n";
|
|
||||||
dlclose(h);
|
dlclose(h);
|
||||||
std::cout << "closed handle\n";
|
std::cout << "successfully dlclosed\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[]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user