diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-04-29 08:17:30 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-04-29 08:17:36 +0200 |
commit | f90a5705bd65a4ebb5edc9df003a383039fec555 (patch) | |
tree | f0180d946bddc15a0a13d9148562418cb3a4108e /src/Video.cpp | |
parent | 68dcd3c4e17355e1c2b640fe1382743d7cb61ea2 (diff) |
Change design, fix crash when closing application
Diffstat (limited to 'src/Video.cpp')
-rw-r--r-- | src/Video.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Video.cpp b/src/Video.cpp index 7b6dcee..4ef3128 100644 --- a/src/Video.cpp +++ b/src/Video.cpp @@ -52,7 +52,8 @@ namespace dchat context(sf::ContextSettings(), width, height), mpv(nullptr), mpvGl(nullptr), - textureBuffer(new sf::Uint8[width * height * 4]) // 4 = red, green, blue and alpha + textureBuffer(new sf::Uint8[width * height * 4]), // 4 = red, green, blue and alpha + alive(true) { context.setActive(true); @@ -84,7 +85,7 @@ namespace dchat renderThread = thread([this, width, height]() { context.setActive(true); - while(true) + while(alive) { while(true) { @@ -92,7 +93,7 @@ namespace dchat if(mpvEvent->event_id == MPV_EVENT_NONE) break; else if(mpvEvent->event_id == MPV_EVENT_SHUTDOWN) - break; + return; } if(redrawCounter > 0) @@ -111,7 +112,6 @@ namespace dchat this_thread::sleep_for(chrono::milliseconds(10)); } }); - renderThread.detach(); const char *cmd[] = { "loadfile", file, nullptr }; mpv_command(mpv, cmd); @@ -120,6 +120,9 @@ namespace dchat Video::~Video() { + alive = false; + renderThread.join(); + lock_guard<mutex> lock(renderMutex); context.setActive(true); if(mpvGl) @@ -128,8 +131,6 @@ namespace dchat delete[] textureBuffer; mpv_opengl_cb_uninit_gl(mpvGl); mpv_detach_destroy(mpv); - if(renderThread.joinable()) - renderThread.join(); } void Video::setPosition(float x, float y) |