FGMouseInput: fix two uses of std::ostringstream
Seeking to the beginning doesn't clear the contents. Note that we don't use std::ostringstream::str() either, because apparently std::ostringstream is too complex to be easily reset to a clean state, so we just recreate an instance every time we need. cf. https://stackoverflow.com/a/12112642/4756009 and https://stackoverflow.com/questions/624260/how-to-reuse-an-ostringstream/624291#comment437178_624276
This commit is contained in:
parent
99c809dda0
commit
21b8c7719e
1 changed files with 5 additions and 3 deletions
|
@ -390,7 +390,10 @@ void FGMouseInput::init()
|
|||
m.mode_node->setIntValue(0);
|
||||
}
|
||||
for (j = 0; j < MAX_MOUSE_BUTTONS; j++) {
|
||||
buf.seekp(ios_base::beg);
|
||||
// According to <https://stackoverflow.com/a/12112642/4756009> and other
|
||||
// similar questions on stackoverflow.com, it seems safer not to try to
|
||||
// reuse the 'buf' variable we have above.
|
||||
std::ostringstream buf;
|
||||
buf << "/devices/status/mice/mouse["<< i << "]/button[" << j << "]";
|
||||
m.mouse_button_nodes[j] = fgGetNode(buf.str().c_str(), true);
|
||||
m.mouse_button_nodes[j]->setBoolValue(false);
|
||||
|
@ -413,9 +416,8 @@ void FGMouseInput::init()
|
|||
|
||||
// Read the button bindings for this mode
|
||||
m.modes[j].buttons.reset(new FGButton[MAX_MOUSE_BUTTONS]);
|
||||
std::ostringstream buf;
|
||||
for (k = 0; k < MAX_MOUSE_BUTTONS; k++) {
|
||||
buf.seekp(ios_base::beg);
|
||||
std::ostringstream buf;
|
||||
buf << "mouse button " << k;
|
||||
m.modes[j].buttons[k].init( mode_node->getChild("button", k), buf.str(), module );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue