parro-it / libui-node

Node bindings for libui, an awesome native UI library for Unix, OSX and Windows
MIT License
1.88k stars 85 forks source link

Crash when OpenFile dialog is closed clicking cancel button #116

Closed son-link closed 6 years ago

son-link commented 6 years ago

I, firts sorry mi english. When i use the OpenFile dialog if i close it or press Cancel the program is crass. This us the error messages:

/home/sonlink/proyectos/vid4web/index.js:31 const filename = libui.UiDialogs.openFile(window); ^ Error: basic_string::_M_construct null not valid at add_btn.onClicked (/home/sonlink/proyectos/vid4web/index.js:31:36)

If i select a file and press Accept works correctly. I use the last release installed with npm

parro-it commented 6 years ago

What OS and version are you using? What Node.js version? Are you able to reproduce the problem using one of the example? (node-pad has an open menu that open a file dialog)

son-link commented 6 years ago

OS: Arch Linux NodeJS: 10.2.1 And, yes, crash in examples/node-pad.js in Open, Save and Save AS

parro-it commented 6 years ago

Ok I'll try to reproduce it.

atilacamurca commented 6 years ago

related to https://github.com/mimecorg/vuido/issues/21

mischnic commented 6 years ago

Yes, it's a libui-node bug.


TL;DR: uiOpenFile returns NULL when aborting and we're then freeing the NULL.


Code from libui/test/page5:

static void openFile(uiButton *b, void *data)
{
    char *fn;

    fn = uiOpenFile(parent);
    if (fn == NULL)
        uiLabelSetText(uiLabel(data), "(cancelled)");
    else {
        uiLabelSetText(uiLabel(data), fn);
        uiFreeText(fn);
    }
}

libui-node: https://github.com/parro-it/libui-node/blob/154e660c7392620d14aba0ade4b346640737b373/src/UiWindow.cc#L166-L171

mischnic commented 6 years ago

Fixed in version 0.2.1