Switched to deque to avoid invalid iterator
authorJesper Krog Poulsen <jesper@krogpoulsen.dk>
Sun, 7 Jun 2015 20:55:27 +0000 (22:55 +0200)
committerJesper Krog Poulsen <jesper@krogpoulsen.dk>
Sun, 7 Jun 2015 20:55:27 +0000 (22:55 +0200)
src/modules/utils/panel/PanelScreen.cpp
src/modules/utils/panel/PanelScreen.h

index 992065c..2049e20 100644 (file)
 #include "libs/StreamOutput.h"
 
 #include <string>
-#include <vector>
+#include <deque>
 
 using namespace std;
 
 // static as it is shared by all screens
-std::vector<std::string> PanelScreen::command_queue;
+std::deque<std::string> PanelScreen::command_queue;
 
 PanelScreen::PanelScreen() {}
 PanelScreen::~PanelScreen() {}
@@ -90,12 +90,12 @@ void PanelScreen::send_command(const char *gcstr)
 void PanelScreen::on_main_loop()
 {
     // for each command in queue send it
-    for (auto& cmd : command_queue) {
+    while(command_queue.size() > 0) {
         struct SerialMessage message;
-        message.message = cmd;
+        message.message = command_queue.front();
+        command_queue.pop_front();
         message.stream = &(StreamOutput::NullStream);
         THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
-        cmd.clear();
     }
     command_queue.clear();
 }
index b249dee..088c3c7 100644 (file)
@@ -9,7 +9,7 @@
 #define PANELSCREEN_H
 
 #include <string>
-#include <vector>
+#include <deque>
 
 class Panel;
 
@@ -37,7 +37,7 @@ protected:
     void send_gcode(std::string g);
     void send_gcode(const char *gm_code, char parameter, float value);
     void send_command(const char *gcstr);
-    static std::vector<std::string> command_queue;
+    static std::deque<std::string> command_queue;
     PanelScreen *parent;
 };