dalerank / sdlgui

Minimalistic port of NanoGUI claim works with SDL API w/o external dependencies.
Other
13 stars 4 forks source link

Crash in void load(Button* ptr) when closing window "fast" #1

Open Ravenbs opened 4 years ago

Ravenbs commented 4 years ago

Hello,

I create a window and close it with:

                myWindow->dispose();
                myWindow= NULL;
                sdlGUIManager->relayout();

If I do this within 5 Seconds -> I get a Nullpointer exception in this function:

  void load(Button* ptr)
  {
    Button* button = ptr;
    AsyncTexture* self = this;
    std::thread tgr([=]() {
      std::lock_guard<std::mutex> guard(button->theme()->loadMutex); <<<<<<<<<<<

Seems when a Window is closed the running rendering threads are not stopped and try to render a deleted object?

Did I do something wrong how to close the window? Took me hours to find out how to close a window, this is not explained in any place (example or documentation) of SDLGui nor in NanoGUI. Seems noone ever closes windows ^^. And for not native speakers "dispose" does not really translate to something realted to "close" "delete" "void",...

Is it normal that the graphic update threads take lots of seconds where the windows are flickering? Any setting to do this syncron or speed window update up to avoid flickering?

Ravenbs commented 4 years ago

Hotfix - remove asyncron doing something (dont know what) by:

  void load(Button* ptr)
  {
    Button* button = ptr;
    AsyncTexture* self = this;
    std::thread tgr([=]() {
      std::lock_guard<std::mutex> guard(button->theme()->loadMutex);

      NVGcontext *ctx = nullptr;
      int realw, realh;
      button->renderBodyTexture(ctx, realw, realh);
      self->tex.rrect = { 0, 0, realw, realh };
      self->ctx = ctx;
      });

    tgr.detach();
  }

to:

  void load(Button* ptr)
  {
    Button* button = ptr;
    AsyncTexture* self = this;
    //std::thread tgr([=]() {
    //  std::lock_guard<std::mutex> guard(button->theme()->loadMutex);

      NVGcontext *ctx = nullptr;
      int realw, realh;
      button->renderBodyTexture(ctx, realw, realh);
      self->tex.rrect = { 0, 0, realw, realh };
      self->ctx = ctx;
      //});

    //tgr.detach();
  }

Then I have no crash closing the window.

Tried to remove this from the other widgets as well - but that makes it insanely slow. 3-4 seconds to render the normal window with a single button. Is this normal?