Wrapped messages can crash draw_messages_window #13

Closed
opened 2026-10-05 03:16:03 +02:00 by adam · 5 comments
Owner

Logic for scrolling the messages window assumes each message is only one line when calculating the max messages/start index/etc for displaying messages. But we also wrap lines, so we can eventually attempt to draw outside the bounds of the messages window, leading to a crash with "addwstr() returned ERR". This only occurs if there are messages long enough to be wrapped and the chat is long enough to require scrolling the messages window.

Chats with traceroutes are especially likely to contain wrapped lines.

Logic for scrolling the messages window assumes each message is only one line when calculating the max messages/start index/etc for displaying messages. But we also wrap lines, so we can eventually attempt to draw outside the bounds of the messages window, leading to a crash with "addwstr() returned ERR". This only occurs if there are messages long enough to be wrapped and the chat is long enough to require scrolling the messages window. Chats with traceroutes are especially likely to contain wrapped lines. <!-- github-sync-id:2796232967 -->
adam closed this issue 2026-10-05 03:16:03 +02:00
Author
Owner

I had to change ui/curses_ui.py to get the msg window to scroll properly. In draw_messages_window() I changed max_messages calc to : max_messages = messages_win.getmaxyx()[0] - 4. Not sure why -4. Also in adjusting the height if log is visible I changed max_messages to just subtract the packetlog_height. max_messages -= packetlog_height. This does not take into account the wrapped messages as explained above. and I use tmux for my terminal session but I don't think it makes a difference. Before these mods once the message screen filled up it would crash...

I had to change ui/curses_ui.py to get the msg window to scroll properly. In draw_messages_window() I changed max_messages calc to : **max_messages = messages_win.getmaxyx()[0] - 4**. Not sure why **-4**. Also in adjusting the height if log is visible I changed max_messages to just subtract the packetlog_height. **max_messages -= packetlog_height**. This does not take into account the wrapped messages as explained above. and I use tmux for my terminal session but I don't think it makes a difference. Before these mods once the message screen filled up it would crash... <!-- github-comment-id:2605483324 -->
Author
Owner

I fixed the above problem by copying the 2 lines that calculate the scoll position to do it again after the dynamic calc based on visible msgs and wraps and it corrected the issue.

I fixed the above problem by copying the 2 lines that calculate the scoll position to do it again after the dynamic calc based on visible msgs and wraps and it corrected the issue. <!-- github-comment-id:2605563132 -->
Author
Owner

I m ay have just gotten lucky with number of wrapped lines working out in #40 There are still issues with drawing messages and scrolling to the bottom of the message list

I m ay have just gotten lucky with number of wrapped lines working out in #40 There are still issues with drawing messages and scrolling to the bottom of the message list <!-- github-comment-id:2605976868 -->
Author
Owner

I think I should be able to get the pad solution into a state where it can be merged in the next couple days, which will fix this and improve the window flashing issue. For a first pass I'm planning to just size the pad so it fits all the messages in the channel and fully refresh it on incoming messages (as we are doing now with the window.) We can further optimize as a follow up.

I think I should be able to get the pad solution into a state where it can be merged in the next couple days, which will fix this and improve the window flashing issue. For a first pass I'm planning to just size the pad so it fits all the messages in the channel and fully refresh it on incoming messages (as we are doing now with the window.) We can further optimize as a follow up. <!-- github-comment-id:2606135121 -->
Author
Owner

That sounds wonderful.

That sounds wonderful. <!-- github-comment-id:2606159922 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/contact#13