From 0e2af5b04f6a861beb919e0dc9e3f80ca0959c92 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Sat, 15 Aug 2020 18:05:18 +0200 Subject: [PATCH] fighting the crash everywhere: random crash at random location. Changing computer might be better idea than changing the code indefinitely... --- CMakeLists.txt | 9 +++--- FrameBuffer.cpp | 14 ++++++---- MediaPlayer.cpp | 6 ++-- Mixer.cpp | 69 +++++++++++++++++++++++++++++++++++----------- Mixer.h | 1 + Scene.cpp | 1 + Session.cpp | 6 ++-- SessionCreator.cpp | 2 +- View.cpp | 5 ++-- View.h | 1 - 10 files changed, 80 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 257f32c..5a19eb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ set(PNG_LIBRARY PNG::PNG) # NB: set glfw3_PATH to /usr/local/Cellar/glfw/3.3.2/lib/cmake/glfw3 # find_package(glfw3 3.2 REQUIRED) -macro_log_feature(glfw3_FOUND "GLFW3" "Open Source, multi-platform library for OpenGL" "http://www.glfw.org/" TRUE) +macro_log_feature(glfw3_FOUND "GLFW3" "Open Source multi-platform library for OpenGL" "http://www.glfw.org/" TRUE) set(GLFW_LIBRARY glfw) #find_package(OpenGL REQUIRED) @@ -108,14 +108,14 @@ set(BUILD_STATIC_LIBS ON) # GLM # add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ext/glm) -message(STATUS "Compiling 'GLM' OpenGL Mathematics https://glm.g-truc.net.") +message(STATUS "Compiling 'GLM' OpenGL mathematics https://glm.g-truc.net.") # # GLAD # set(GLAD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/glad/include) add_library(GLAD "${CMAKE_CURRENT_SOURCE_DIR}/ext/glad/src/glad.c") -message(STATUS "Compiling 'GLAD' generated at https://glad.dav1d.de/ -- ${GLAD_INCLUDE_DIR}.") +message(STATUS "Compiling 'GLAD' Open source multi-language OpenGL loader https://glad.dav1d.de/ -- ${GLAD_INCLUDE_DIR}.") # # DEAR IMGUI @@ -357,8 +357,8 @@ message(STATUS "Using 'CMakeRC ' from https://github.com/vector-of-bool/cmrc.git target_link_libraries(${VMIX_BINARY} LINK_PRIVATE ${GLFW_LIBRARY} -# ${OPENGL_LIBRARY} GLAD + glm::glm ${CMAKE_DL_LIBS} ${GOBJECT_LIBRARIES} ${GSTREAMER_LIBRARY} @@ -375,7 +375,6 @@ target_link_libraries(${VMIX_BINARY} LINK_PRIVATE TINYXML2 TINYFD IMGUI - glm::glm vmix::rc ) diff --git a/FrameBuffer.cpp b/FrameBuffer.cpp index 767f1a2..4de5a70 100644 --- a/FrameBuffer.cpp +++ b/FrameBuffer.cpp @@ -21,13 +21,17 @@ glm::vec3 FrameBuffer::getResolutionFromParameters(int ar, int h) return res; } -FrameBuffer::FrameBuffer(glm::vec3 resolution, bool useAlpha, bool multiSampling): textureid_(0), intermediate_textureid_(0), framebufferid_(0), intermediate_framebufferid_(0), use_alpha_(useAlpha), use_multi_sampling_(multiSampling) +FrameBuffer::FrameBuffer(glm::vec3 resolution, bool useAlpha, bool multiSampling): + textureid_(0), intermediate_textureid_(0), framebufferid_(0), intermediate_framebufferid_(0), + use_alpha_(useAlpha), use_multi_sampling_(multiSampling) { attrib_.viewport = glm::ivec2(resolution); attrib_.clear_color = glm::vec4(0.f, 0.f, 0.f, use_alpha_ ? 0.f : 1.f); } -FrameBuffer::FrameBuffer(uint width, uint height, bool useAlpha, bool multiSampling): textureid_(0), intermediate_textureid_(0), framebufferid_(0), intermediate_framebufferid_(0), use_alpha_(useAlpha), use_multi_sampling_(multiSampling) +FrameBuffer::FrameBuffer(uint width, uint height, bool useAlpha, bool multiSampling): + textureid_(0), intermediate_textureid_(0), framebufferid_(0), intermediate_framebufferid_(0), + use_alpha_(useAlpha), use_multi_sampling_(multiSampling) { attrib_.viewport = glm::ivec2(width, height); attrib_.clear_color = glm::vec4(0.f, 0.f, 0.f, use_alpha_ ? 0.f : 1.f); @@ -63,14 +67,14 @@ void FrameBuffer::init() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); - // attach the multisampled texture to FBO (currently binded) + // attach the multisampled texture to FBO (framebufferid_ currently binded) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, intermediate_textureid_, 0); - // create an intermediate FBO + // create an intermediate FBO : this is the FBO to use for reading glGenFramebuffers(1, &intermediate_framebufferid_); glBindFramebuffer(GL_FRAMEBUFFER, intermediate_framebufferid_); - // attach the 2D texture to intermediate FBO + // attach the 2D texture to intermediate FBO (intermediate_framebufferid_) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureid_, 0); // Log::Info("New FBO %d Multi Sampling ", framebufferid_); diff --git a/MediaPlayer.cpp b/MediaPlayer.cpp index a5f4f8a..99a19af 100644 --- a/MediaPlayer.cpp +++ b/MediaPlayer.cpp @@ -77,6 +77,8 @@ static MediaInfo UriDiscoverer_(std::string uri) #endif MediaInfo video_stream_info; + // assume it will fail + video_stream_info.failed = true; /* Instantiate the Discoverer */ GError *err = NULL; @@ -123,6 +125,8 @@ static MediaInfo UriDiscoverer_(std::string uri) GstDiscovererStreamInfo *tmpinf = (GstDiscovererStreamInfo *) tmp->data; if ( GST_IS_DISCOVERER_VIDEO_INFO(tmpinf) ) { + // inform that it succeeded + video_stream_info.failed = false; // found a video / image stream : fill-in information GstDiscovererVideoInfo* vinfo = GST_DISCOVERER_VIDEO_INFO(tmpinf); video_stream_info.width = gst_discoverer_video_info_get_width(vinfo); @@ -167,8 +171,6 @@ static MediaInfo UriDiscoverer_(std::string uri) gst_discoverer_stream_info_list_free(streams); if (!foundvideostream) { - // inform that it failed - video_stream_info.failed = true; Log::Warning("Warning: No video stream in '%s'", uri.c_str()); } } diff --git a/Mixer.cpp b/Mixer.cpp index 0735226..ed470be 100644 --- a/Mixer.cpp +++ b/Mixer.cpp @@ -26,7 +26,7 @@ using namespace tinyxml2; #include "Mixer.h" -#define THREADED_LOADING +//#define THREADED_LOADING // static semaphore to prevent multiple threads for load / save static std::atomic sessionThreadActive_ = false; @@ -40,17 +40,19 @@ static Session *loadSession_(const std::string& filename) { Session *s = new Session; - // actual loading of xml file - SessionCreator creator( s ); + if (s) { + // actual loading of xml file + SessionCreator creator( s ); - if (creator.load(filename)) { - // loaded ok - s->setFilename(filename); - } - else { - // error loading - delete s; - s = nullptr; + if (creator.load(filename)) { + // loaded ok + s->setFilename(filename); + } + else { + // error loading + delete s; + s = nullptr; + } } return s; @@ -148,6 +150,14 @@ Mixer::Mixer() : session_(nullptr), back_session_(nullptr), current_view_(nullpt void Mixer::update() { + if (garbage_.size()>0) { + + delete garbage_.back(); + garbage_.pop_back(); + } + + +#ifdef THREADED_LOADING // if there is a session importer pending if (!sessionImporters_.empty()) { // check status of loader: did it finish ? @@ -169,6 +179,7 @@ void Mixer::update() sessionLoaders_.pop_back(); } } +#endif // if a change of session is requested if (sessionSwapRequested_) { @@ -588,10 +599,32 @@ void Mixer::saveas(const std::string& filename) void Mixer::load(const std::string& filename) { + +#ifdef THREADED_LOADING // load only one at a time if (sessionLoaders_.empty()) { + // Start async thread for loading the session + // Will be obtained in the future in update() sessionLoaders_.emplace_back( std::async(std::launch::async, loadSession_, filename) ); + + +// Session *se = new Session; + +// sessionLoaders_.emplace_back(std::async(std::launch::async, +// [](Session *s, const std::string& filename){ +// // actual loading of xml file +// SessionCreator creator( s ); +// if (creator.load(filename)) { +// // loaded ok +// s->setFilename(filename); +// } +// return s; +// }, se, filename)); + } +#else + set( loadSession_(filename) ); +#endif } void Mixer::open(const std::string& filename) @@ -622,9 +655,10 @@ void Mixer::import(const std::string& filename) { // import only one at a time if (sessionImporters_.empty()) { + // Start async thread for loading the session + // Will be obtained in the future in update() sessionImporters_.emplace_back( std::async(std::launch::async, loadSession_, filename) ); } - } void Mixer::merge(Session *session) @@ -695,8 +729,9 @@ void Mixer::swap() // reset timer update_time_ = GST_CLOCK_TIME_NONE; - // delete back - delete back_session_; + // delete back (former front session) +// delete back_session_; + garbage_.push_back(back_session_); back_session_ = nullptr; // notification @@ -724,7 +759,8 @@ void Mixer::clear() { // delete previous back session if needed if (back_session_) - delete back_session_; + garbage_.push_back(back_session_); +// delete back_session_; // create empty session back_session_ = new Session; @@ -744,7 +780,8 @@ void Mixer::set(Session *s) // delete previous back session if needed if (back_session_) - delete back_session_; + garbage_.push_back(back_session_); +// delete back_session_; // set to new given session back_session_ = s; diff --git a/Mixer.h b/Mixer.h index 2192f02..02d12ff 100644 --- a/Mixer.h +++ b/Mixer.h @@ -82,6 +82,7 @@ protected: Session *session_; Session *back_session_; + std::list garbage_; bool sessionSwapRequested_; void swap(); diff --git a/Scene.cpp b/Scene.cpp index d66f4b2..1325105 100644 --- a/Scene.cpp +++ b/Scene.cpp @@ -438,6 +438,7 @@ Scene::Scene() Scene::~Scene() { + clear(); // bg and fg are deleted as children of root delete root_; } diff --git a/Session.cpp b/Session.cpp index 8fdbae1..c8db024 100644 --- a/Session.cpp +++ b/Session.cpp @@ -9,10 +9,12 @@ #include "Log.h" -Session::Session() : filename_(""), failedSource_(nullptr), active_(true), fading_target_(0.f) +Session::Session() : failedSource_(nullptr), active_(true), fading_target_(0.f) { + filename_ = ""; + config_[View::RENDERING] = new Group; - config_[View::RENDERING]->scale_ = render_.resolution(); + config_[View::RENDERING]->scale_ = FrameBuffer::getResolutionFromParameters(Settings::application.render.ratio, Settings::application.render.res); config_[View::GEOMETRY] = new Group; config_[View::GEOMETRY]->scale_ = Settings::application.views[View::GEOMETRY].default_scale; diff --git a/SessionCreator.cpp b/SessionCreator.cpp index 60db4f8..54d329f 100644 --- a/SessionCreator.cpp +++ b/SessionCreator.cpp @@ -193,7 +193,7 @@ void SessionCreator::visit(MediaPlayer &n) GstClockTime b = GST_CLOCK_TIME_NONE; gap->QueryUnsigned64Attribute("begin", &a); gap->QueryUnsigned64Attribute("end", &b); - n.timeline().addGap( a, b ); // TODO ref access to timeline of source + n.timeline().addGap( a, b ); } } // playing properties diff --git a/View.cpp b/View.cpp index 240238c..ca65fec 100644 --- a/View.cpp +++ b/View.cpp @@ -541,7 +541,7 @@ uint MixingView::textureMixingQuadratic() RenderView::RenderView() : View(RENDERING), frame_buffer_(nullptr), fading_overlay_(nullptr) { - // set resolution to settings or default + // set resolution to settings default setResolution(); } @@ -571,7 +571,8 @@ float RenderView::fading() const void RenderView::setResolution(glm::vec3 resolution) { - if (resolution.x < 128.f || resolution.y < 128.f) + // use default resolution if invalid resolution is given (default behavior) + if (resolution.x < 2.f || resolution.y < 2.f) resolution = FrameBuffer::getResolutionFromParameters(Settings::application.render.ratio, Settings::application.render.res); // do we need to change resolution ? diff --git a/View.h b/View.h index 5ac3e7c..289ba43 100644 --- a/View.h +++ b/View.h @@ -113,7 +113,6 @@ private: class RenderView : public View { - FrameBuffer *intermediate_buffer_; FrameBuffer *frame_buffer_; Surface *fading_overlay_;