gchp/rustbox

Using InputMode::Mouse triggers termbox assertion

panicbit opened this issue · 11 comments

Using termbox.set_input_mode(InputMode::Mouse) and poll_event(…) triggers an assertion in termbox. It doesn't seem to trigger imediately after a poll but when deinitializing rust-/termbox.

Here's a minimal example:

extern crate rustbox;

fn main() {
    let rustbox = rustbox::RustBox::init(Default::default()).unwrap();
    rustbox.set_input_mode(rustbox::InputMode::Mouse);
    rustbox.poll_event(true);
}

What's weird, though, is that the equivalent C program does not trigger the assertion:

#include "termbox.h"

int main(int argc, char **argv) {
    tb_init();
    tb_select_input_mode(TB_INPUT_MOUSE);

    struct tb_event ev;
    tb_poll_event(&ev);

    tb_shutdown();
    return 0;
}
sru commented

Both programs throw error on pressing escape key and only escape key. They do not throw error on other keys however. It's probably a bug in Termbox since tb_select_input_mode assigns the mode, overriding previous modes (reference). Therefore the assertion triggers because mode does not contain either TB_INPUT_ESC or TB_INPUT_ALT.

@sru I can not confirm this. I definitely don't get an assertion when pressing escape in the C version.

sru commented

@panicbit That's odd. Maybe it's platform specific? I have only tested on Mac OS X (10.9.5), but I can try it on Linux later, when I get home. And I don't even know if Termbox runs on Windows.

@sru Or it might have to do with the terminal emulator used. I'm running ArchLinux and gnome-terminal.

sru commented

@panicbit Might be. I am running iTerm, and it's messing up my terminal with bloat of characters written by the mouse input after the assertion :(

@sru You should be able to issue reset which should fix that.

sru commented

@panicbit Huh, thanks for the tip!

sru commented

@panicbit I still get the assertion only when pressing escape in C version using Archlinux and rxvt-unicode. It might be the terminal emulator.

@sru Still no issues using (C version, rxvt-unicode-9.21, nsf/termbox@7c154d98)

The way I build termbox and run the example:

python2 setup.py build
cp build/lib.*/termbox.so libtermbox.so       
gcc -ltermbox -L. -Isrc/ example.c -o example
LD_LIBRARY_PATH=. ./example

@sru I linked termbox statically now and I'm getting the assertion!

This is fixed now in termbox