Skip to content

Commit

Permalink
Merge pull request #5280 from ab9rf/fix-win-console-hang
Browse files Browse the repository at this point in the history
Fix win console hang
  • Loading branch information
myk002 authored Feb 17, 2025
2 parents c138083 + d7100be commit 282f235
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Template for new versions:
- `spectate`: when spectate mode is enabled, left/right arrow will cycle through following next/prevous units

## Fixes
- Windows console: fix possible hang if the console returns a too-small window width (for any reason)
- `createitem`: output items will now end up at look cursor if active
- `spectate`: don't allow temporarily modified announcement settings to be written to disk when "auto-unpause" mode is enabled
- `changevein`: fix a crash that could occur when attempting to change a vein into itself
Expand Down
18 changes: 8 additions & 10 deletions library/Console-windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/


#define NOMINMAX
#include <windows.h>
#include <conio.h>
#include <stdarg.h>
Expand Down Expand Up @@ -232,16 +233,13 @@ namespace DFHack
size_t len = raw_buffer.size();
int cooked_cursor = raw_cursor;

while ((plen + cooked_cursor) >= cols)
{
buf++;
len--;
cooked_cursor--;
}
while (plen + len > cols)
{
len--;
}
int adj = std::min(plen + cooked_cursor - cols, len);
buf += adj;
len -= adj;
cooked_cursor -= adj;

int adj2 = std::min(plen + len - cols, len);
len -= adj2;

CONSOLE_SCREEN_BUFFER_INFO inf = { 0 };
GetConsoleScreenBufferInfo(console_out, &inf);
Expand Down

0 comments on commit 282f235

Please sign in to comment.