Crash on terminal resize when waiting for events. #22

Closed
jesskay opened this Issue Sep 5, 2013 · 10 comments

2 participants

@jesskay

I'm not sure precisely what's going on, though I've managed to narrow it down to what I believe to be the smallest crashing piece of code (if it was real code I'd probably issue a close() at the end, but it never gets there anyway in this demonstration).

If I run the following script:

import termbox

tb = termbox.Termbox()

while True:
    tb.poll_event()

and then attempt to resize my terminal (both when resizing panes in tmux and resizing an xterm that it's running directly under), more often than not python will abort, simply dumping out this message:

python3.2: src/termbox.c:521: wait_fill_event: Assertion `r > 0' failed.

This also happens when using peek_event, and does not seem to be affected by the timeout passed to peek_event. It does not occur on key events, at least so far as I can tell.

As I said before, I'm really not sure what's going on here, and I don't imagine what I've got so far is all that helpful, so any advice on how to get a more useful crash dump would be much appreciated.

@nsf
Owner
nsf commented Sep 5, 2013

Yes, confirmed, will fix that.

@nsf nsf closed this in 104ed5a Sep 5, 2013
@jesskay

I'm unsure if this is related, but since reinstalling with the fixed code, I now encounter a new problem on attempting to resize: I get spurious key events (I'd speculate they're the resize escape codes, but I could be entirely wrong), including occasionally some that crash termbox with this error:

File "termboxmodule.pyx", line 238, in termbox.Termbox.peek_event (src/python/termboxmodule.c:2487)
ValueError: chr() arg not in range(0x110000)
@nsf
Owner
nsf commented Sep 5, 2013

Yep, that's weird. What was weird in the first place that code which is related to input handling is triggering when you resize a window. Which shouldn't happen at all. What's your OS?

@nsf
Owner
nsf commented Sep 5, 2013

There is no such thing as resize escape codes.

@nsf
Owner
nsf commented Sep 5, 2013

Maybe some weird terminal settings you're using?

@jesskay

Ah, alright. I was probably misremembering something about escape codes and terminal size. And I'm on Gentoo Linux, on an amd64 architecture.

I managed to dump out a list of the returned tuples of the spurious key events, no idea if they make any sense to you:

(1, None, 24, 0, 0, 0)
(1, None, 7, 0, 0, 0)
(1, '\udb2d', 0, 0, 0, 0)
(1, None, 127, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, '0', 0, 0, 0, 0)
(1, '긁', 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, '\x18', 0, 0, 0, 0)
(1, 'b', 0, 0, 0, 0)
(1, '櫭', 0, 0, 0, 0)
(1, None, 127, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, '8', 0, 0, 0, 0)
(1, 'a', 0, 0, 0, 0)
(1, '櫭', 0, 0, 0, 0)
(1, None, 127, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, 'o', 0, 0, 0, 0)
(1, '.', 0, 0, 0, 0)
(1, '쭿', 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, '`', 0, 0, 0, 0)
(1, 'b', 0, 0, 0, 0)
(1, '櫭', 0, 0, 0, 0)
(1, None, 127, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, 'خ', 0, 0, 0, 0)
(1, '嫭', 0, 0, 0, 0)
(1, None, 127, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 8, 0, 0, 0)
(1, 'c', 0, 0, 0, 0)
(1, '櫭', 0, 0, 0, 0)
(1, None, 127, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, None, 0, 0, 0, 0)
(1, 'q', 0, 0, 0, 0)

That was from reducing the width by one column, in a regular xterm with no settings changed from default.

@jesskay

And just for completeness since it's Gentoo and thus compilation options depend on this: the xterm I'm using was built with USE="openpty truetype unicode -Xaw3d -toolbar", and is version 293.

@nsf
Owner
nsf commented Sep 5, 2013

The key events are complete garbage. Hm.. actually you know what, it looks like a buffer overflow on my side. Will check that out.

@nsf
Owner
nsf commented Sep 5, 2013

Yep, sorry about that :D Try it now.

@jesskay

Yep, it seems to work exactly as intended now. Thanks for your help! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment