diff --git a/src/c_console.cpp b/src/c_console.cpp index 691c4a3ca7..0a324eb8ff 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -1523,8 +1523,6 @@ static bool C_HandleKey (event_t *ev, FCommandBuffer &buffer) buffer.Text.StripLeftRight(); Printf(127, TEXTCOLOR_WHITE "]%s\n", buffer.Text.GetChars()); - AddCommandString(buffer.Text.LockBuffer()); - buffer.Text.UnlockBuffer(); if (buffer.Text.Len() == 0) { @@ -1568,7 +1566,21 @@ static bool C_HandleKey (event_t *ev, FCommandBuffer &buffer) } } HistPos = NULL; - buffer.SetString(""); + { + // Work with a copy of command to avoid side effects caused by + // exception raised during execution, like with 'error' CCMD. + // It's problematic to maintain FString's lock symmetry. + static TArray command; + const size_t length = buffer.Text.Len(); + + command.Resize(length + 1); + memcpy(&command[0], buffer.Text.GetChars(), length); + command[length] = '\0'; + + buffer.SetString(""); + + AddCommandString(&command[0]); + } TabbedLast = false; TabbedList = false; break;