From 3198ce59f7e2cc1d368a90866ecec205a95c847a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFse=20Brosseau?= <54746458+eloisebrosseau@users.noreply.github.com> Date: Wed, 27 May 2026 09:48:34 +0800 Subject: [PATCH 1/2] fix: SG-42890: Fix BADACCESS X error when running RVIO commands on Rocky Linux 9 (OpenRV #1249) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### SG-42890: Fix BADACCESS X error when running RVIO commands on Rocky Linux 9 ### Summarize your change. - [X] Make the writer thread call MovieRV::uninit instead of the main thread - [X] Replace dummyDev raw pointer with an FBOVideoDevice unique_ptr ### Describe the reason for the change. https://github.com/AcademySoftwareFoundation/OpenRV/pull/310 added `MovieRV::uninit` in the main function of RVIO to fix a GL error on exit on Rocky Linux 9. However, in a more recent version of the Rocky Linux 9, we are now getting a BADACCESS X error when running RVIO commands from the command line. An alert panel is also being displayed when submitting an image sequence through Screening Room after each step. This was caused by the main thread trying to access the OpenGL rendering context used by the writer thread when calling `MovieRV::uninit` at the end of the main function. It seems that the initial GL error was actually caused by the FBOVideoDevice raw pointer created as a dummy video device at the beginning of the main RVIO function by the main thread to avoid a segmentation fault. This raw pointer was never deleted, and this was causing a GL error when the `GLSyncObjectARBSync` destructor was called at the end of the program. Replacing the raw pointer with a unique_ptr fixed the leaking pointer that was the root cause of the GL error. `MovieRV::uninit` was not technically needed to fix the original GL error, but it's a good practice to keep it to make sure we uninit any FBOs that were allocated. The only difference is that it should have been called by the writer thread instead of the main thread since it is the one that actually created and used the FBOVideoDevice and the OpenGL rendering context during the execution of RVIO. ### Describe what you have tested and on which operating system. Submitting an image sequence through Screening Room was tested on Rocky Linux 9.6, Windows 11, and macOS 26.3. The following commands that were called during the submit process of Screening Room were also manually called from the command line to make sure no error remains: - `rvio movie.####.dpx -o /tmp/thumb.#.jpg` - `rvio movie.####.dpx -o /tmp/out.mov` - `rvio movie.####.dpx -resize 240 132 -outres 1200 132 -o /tmp/filmstrip.jpg` --------- Signed-off-by: Éloïse Brosseau (cherry picked from commit 9fb070bc4ac64d8e570aa3170fe299130ae9dabb) UTV: utvio no longer has the OSMesa path, so only the FBOVideoDevice change applies. The finalize also runs on the Windows ThreadedMovie path (upstream changed only the pthread one), and it deletes the PBO pools' buffers from #145 too, since that needs the writer thread's context as well. Signed-off-by: Michael Oliver --- src/bin/imgtools/rvio/main.cpp | 47 ++++++++++--------- src/lib/image/TwkMovie/ThreadedMovie.cpp | 12 ++++- .../image/TwkMovie/TwkMovie/ThreadedMovie.h | 5 +- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/bin/imgtools/rvio/main.cpp b/src/bin/imgtools/rvio/main.cpp index 12458e20..a006b912 100644 --- a/src/bin/imgtools/rvio/main.cpp +++ b/src/bin/imgtools/rvio/main.cpp @@ -68,6 +68,7 @@ #include #include #include +#include #include #include #include @@ -384,6 +385,27 @@ void threadedMovieInit() #endif } +// +// Runs on the writer thread once it has rendered the last frame. The GL +// context is current on that thread, and making it current on the main +// thread fails (BadAccess on GLX and EGL, silently on WGL). +// + +void threadedMovieFinalize() +{ + // clean up any frame buffers we allocated writing the movie + MovieRV::uninit(); + + // + // Delete the pixel buffer objects while the GL context is still + // current. Left to the pools' static destructors, glDeleteBuffers + // runs after the GL library has shut down, which crashes at exit + // with Mesa. + // + + TwkGLF::DeletePBOPoolBuffers(); +} + TwkMovie::Movie* makeLeaderMovie(MovieWriter::WriteRequest& writeRequest, TwkMovie::Movie* omov, Mu::MuLangContext* context, Mu::Process* process) { @@ -981,13 +1003,7 @@ int utf8Main(int argc, char* argv[]) setEnvVar("LC_ALL", "C"); TwkFB::ThreadPool::initialize(); - // - // XXX dummyDev is leaking here. Best would be to pass it to the App so - // that it could delete it after startup, since it's no longer needed at - // that point. - // - - TwkGLF::FBOVideoDevice* dummyDev = new TwkGLF::FBOVideoDevice(0, 10, 10, false); + auto dummyDev = std::make_unique(nullptr, 10, 10, false); IPCore::ImageRenderer::queryGL(); const char* glVersion = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); IPCore::Shader::Function::useShadingLanguageVersion(glVersion); @@ -1662,13 +1678,13 @@ int utf8Main(int argc, char* argv[]) #ifdef WIN32 GC_INIT(); GC_allow_register_threads(); - outmov = new ThreadedMovie(inputMovies, outFrames, 8, 0, threadedMovieInit); + outmov = new ThreadedMovie(inputMovies, outFrames, 8, 0, threadedMovieInit, threadedMovieFinalize); #else ThreadedMovie::ThreadAPI threadAPI; threadAPI.create = GC_pthread_create; threadAPI.join = GC_pthread_join; threadAPI.detach = GC_pthread_detach; - outmov = new ThreadedMovie(inputMovies, outFrames, 8, &threadAPI, threadedMovieInit); + outmov = new ThreadedMovie(inputMovies, outFrames, 8, &threadAPI, threadedMovieInit, threadedMovieFinalize); #endif #endif @@ -1770,19 +1786,6 @@ int utf8Main(int argc, char* argv[]) if (!writer->write(outmov, outfile, writeRequest)) exit(-2); - - // clean up any frame buffers we allocated writing the movie - // - MovieRV::uninit(); - - // - // Delete the pixel buffer objects while the GL context is still - // current. Left to the pools' static destructors, glDeleteBuffers - // runs after the GL library has shut down, which crashes at exit - // with Mesa. - // - - TwkGLF::DeletePBOPoolBuffers(); } catch (TwkExc::Exception& exc) { diff --git a/src/lib/image/TwkMovie/ThreadedMovie.cpp b/src/lib/image/TwkMovie/ThreadedMovie.cpp index c911e84e..005beed5 100644 --- a/src/lib/image/TwkMovie/ThreadedMovie.cpp +++ b/src/lib/image/TwkMovie/ThreadedMovie.cpp @@ -19,7 +19,8 @@ namespace TwkMovie mov->threadMain(); } - ThreadedMovie::ThreadedMovie(const Movies& movies, const Frames& frames, size_t stackMultiplier, ThreadAPI* api, InitializeFunc F) + ThreadedMovie::ThreadedMovie(const Movies& movies, const Frames& frames, size_t stackMultiplier, ThreadAPI* api, InitializeFunc F, + FinalizeFunc finalizeFunction) : m_movies(movies) , m_threadGroup(movies.size(), stackMultiplier, api) , m_frames(frames) @@ -27,6 +28,7 @@ namespace TwkMovie , m_currentIndex(0) , m_requestIndex(0) , m_initialize(F) + , m_finalize(finalizeFunction) { // if (!m_movie->isThreadSafe()) throw runtime_exception(); m_info = movies.front()->info(); @@ -188,8 +190,16 @@ namespace TwkMovie m_threadGroup.lock(m_runLock); td->running = false; + + bool allFramesDone = (m_currentIndex >= m_frames.size()); + m_threadGroup.unlock(m_runLock); + if (allFramesDone && m_finalize != nullptr) + { + m_finalize(); + } + // cout << "thread " << td->id << " no longer running" << endl; } diff --git a/src/lib/image/TwkMovie/TwkMovie/ThreadedMovie.h b/src/lib/image/TwkMovie/TwkMovie/ThreadedMovie.h index 11b0f745..18d71d0b 100644 --- a/src/lib/image/TwkMovie/TwkMovie/ThreadedMovie.h +++ b/src/lib/image/TwkMovie/TwkMovie/ThreadedMovie.h @@ -57,8 +57,10 @@ namespace TwkMovie typedef std::vector Movies; typedef stl_ext::thread_group::thread_api ThreadAPI; typedef void (*InitializeFunc)(); + using FinalizeFunc = void (*)(); - ThreadedMovie(const Movies&, const Frames& frames, size_t stackMultiplier = 8, ThreadAPI* api = 0, InitializeFunc = NULL); + ThreadedMovie(const Movies&, const Frames& frames, size_t stackMultiplier = 8, ThreadAPI* api = nullptr, InitializeFunc = nullptr, + FinalizeFunc = nullptr); virtual ~ThreadedMovie(); @@ -104,6 +106,7 @@ namespace TwkMovie int m_requestIndex; bool m_init; InitializeFunc m_initialize; + FinalizeFunc m_finalize; }; } // namespace TwkMovie From 75badc41023349eb2300232b5c6ceb3aedc93628 Mon Sep 17 00:00:00 2001 From: Bernard Laberge <117092886+bernie-laberge@users.noreply.github.com> Date: Wed, 27 May 2026 13:10:40 -0400 Subject: [PATCH 2/2] fix: SG-42890: Fix SEGV error when running RVIO commands on Rocky Linux 9 (part 2) (OpenRV #1279) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### fix: SG-42890: Fix SIGSEGV error when running RVIO commands on Rocky Linux 9 (part 2) ### Linked issues NA ### Summarize your change. Fix an `rvio` SIGSEGV that fires at shutdown on Linux with the NVIDIA proprietary GL driver. Conversions complete successfully — the output `.mov` is written intact — but the process then exits with a segfault, which produces a crash dump and a non-zero exit code that breaks RV/CI/render-farm pipelines. Symptoms: - All frames are rendered and the output file is fully written. - The process then segfaults after `main()` returns. - Crashpad-symbolicated minidump shows the crashing thread's `rip` in an unmapped region with no usable call stack (only `stack scanning` frames in `libc.so.6`). The crash address looks like garbage because the page is already gone by the time the dump is written. Constant register signatures across ASLR-randomized runs (`rax=0x6e`, `r14=0x1e8480`, `r15=0xfffffffffffffb28`) confirmed the crash always lands at the same instruction. ### Root cause Captured under `gdb` (where the offending library is still mapped at the instant of the SIGSEGV), the crashing thread is an NVIDIA driver background worker: ``` Thread N "RVIO Main" received signal SIGSEGV 0x00007fffcd9f59ec in ?? () from /lib64/libnvidia-glcore.so.595.58.03 #0 libnvidia-glcore.so.595.58.03 #1 libnvidia-glcore.so.595.58.03 #2 libnvidia-glcore.so.595.58.03 #3 start_thread () from libc.so.6 #4 clone3 () from libc.so.6 ``` …while the main thread is mid-teardown: ``` #0 _dl_close_worker (...) at dl-close.c:769 #1 _dl_close #2 __GI__dl_catch_exception #5 dlclose@GLIBC_2.2.5 () #6 __glXMappingTeardown () from libGLX.so.0 #7 __glXFini () from libGLX.so.0 #8 _dl_fini () at dl-fini.c:148 #9 __run_exit_handlers () from libc.so.6 #10 exit () from libc.so.6 ``` This is the well-known **libglvnd ↔ NVIDIA driver shutdown race**: 1. `main()` returns. 2. libc's `exit()` runs `__run_exit_handlers` → `_dl_fini`. 3. `_dl_fini` invokes `libGLX.so.0`'s ELF destructor `__glXFini`, which `dlclose`s the NVIDIA GLX vendor (`libGLX_nvidia.so.0`) and transitively unmaps `libnvidia-glcore.so`. 4. NVIDIA's proprietary driver maintains its own internal helper threads. They are **not** joined by libglvnd's teardown — NVIDIA's blob has no such hook. The threads are still running when `dlclose` finishes. 5. The kernel unmaps `libnvidia-glcore.so`'s code pages out from under one of those running threads → next instruction fetch hits unmapped memory → SIGSEGV. The thread is named `"RVIO Main"` only because Linux child threads inherit their parent's `prctl(PR_SET_NAME)` value (set by `TwkUtil::setThreadName`). It is NOT the application's main thread. By the time crashpad's signal handler finishes serializing the minidump, `dlclose` has fully completed and the page is no longer in `/proc/self/maps`, which is why the dump appeared to crash "nowhere." ### Solution `src/bin/imgtools/rvio/main.cpp`: on Linux, replace the final `return 0;` in `utf8Main` with `std::_Exit(0);` — but only after all of rvio's legitimate shutdown has already run (`MovieRV::uninit`, `TwkMovie::GenericIO::shutdown`, `TwkFB::GenericIO::shutdown`, `TwkFB::ThreadPool::shutdown`). `std::_Exit` is the POSIX "skip atexit / `_dl_fini` and terminate now" primitive. It hands control directly to the kernel, which reaps memory, file descriptors, and threads — including NVIDIA's straggler threads — atomically, with no opportunity for the unload race. Nothing in our shutdown is left undone: - The output movie has already been finalized and `close`d by the writer before `utf8Main` reaches this point. - All Open RV-owned plugins have been shut down explicitly above the `_Exit` call. Windows and macOS still go through `return 0;` because they don't use libglvnd and don't exhibit this race. The change is `#ifdef PLATFORM_LINUX` guarded. Signed-off-by: Bernard Laberge (cherry picked from commit 6219ece6f3efc1e8f86fc6b2521c39e3fba6b3d8) Signed-off-by: Michael Oliver UTV: flush stdout, stderr and C stdio before _Exit, which skips that. Matters for utvio -v output redirected to a log. --- src/bin/imgtools/rvio/main.cpp | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/bin/imgtools/rvio/main.cpp b/src/bin/imgtools/rvio/main.cpp index a006b912..0f0283ae 100644 --- a/src/bin/imgtools/rvio/main.cpp +++ b/src/bin/imgtools/rvio/main.cpp @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -1812,5 +1813,39 @@ int utf8Main(int argc, char* argv[]) TwkFB::GenericIO::shutdown(); // Shutdown TwkFB::GenericIO plugins TwkFB::ThreadPool::shutdown(); + +#ifdef PLATFORM_LINUX + // + // Workaround for the libglvnd <-> NVIDIA driver shutdown race. + // + // Returning normally from main() triggers libc's exit handlers, which + // run _dl_fini. _dl_fini invokes each linked library's destructor, + // including libGLX.so.0's __glXFini, which calls + // __glXMappingTeardown -> dlclose("libGLX_nvidia.so.0"). + // + // Note: libglvnd (GL Vendor-Neutral Dispatch library) is the dispatch + // layer that sits between an application's OpenGL/GLX/EGL calls + // and the actual vendor driver on Linux. + // + // The NVIDIA closed-source driver spawns internal helper threads + // (idle/event loops inside libnvidia-glcore.so) that libglvnd has no + // hook to join. The dlclose therefore unmaps libnvidia-glcore.so while + // those threads are still running, and their next instruction fetch + // lands on an unmapped page -> SIGSEGV at process exit. + // + // Calling std::_Exit(0) instead of returning skips atexit/_dl_fini and + // lets the kernel reap memory, threads, and file descriptors directly. + // This is safe here: by this point rvio's own shutdown is complete + // (the output movie is closed, MovieRV/GenericIO/ThreadPool have all + // been torn down), so there is no remaining cleanup that the exit + // handlers would have done for us, except flushing stdio: _Exit + // doesn't, and output redirected to a file or pipe would be lost. + // + std::cout.flush(); + std::cerr.flush(); + std::fflush(nullptr); + std::_Exit(0); +#endif + return 0; }