Fix SIGSEGV from HDF5 library teardown and concurrent access - #13
Open
chraibi wants to merge 1 commit into
Open
Conversation
The bundled HDF5 is built without thread safety (Threadsafety: OFF in
libhdf5.settings), yet geometry and trajectory loading can read the same
.h5 concurrently from different threads. Worse, CloseFile(), OpenFile()'s
error path and DetectFormat() called H5close(), which shuts down the HDF5
library process-wide and crashes any reader that is mid-operation.
Observed as a SIGSEGV at address 0x20 when one thread ran H5close() while
another was still inside H5open():
Hdf5DataPlugin!H5P__access_class -> H5P_create_id -> H5T_init
-> H5_init_library -> H5open
Hdf5DataPlugin!FHdf5SimulationReader::OpenFile
ProjectMobius!FProcessSimulationDataRunnable::LoadAndDeserializeHDF5File
- Guard every public reader method with a process-wide recursive
critical section.
- Remove all H5close() calls; the library now lives for the process.
H5Fclose() still closes individual files.
There was a problem hiding this comment.
Pull request overview
This PR prevents editor crashes when loading HDF5 simulations by removing process-wide HDF5 shutdown calls (H5close) from the reader and serializing all HDF5 API usage in FHdf5SimulationReader to account for the bundled non-thread-safe HDF5 build.
Changes:
- Introduces a process-wide critical section guard used by all public
FHdf5SimulationReadermethods that touch HDF5. - Removes
H5close()calls fromOpenFile()error paths,CloseFile(), andDetectFormat()so one reader cannot tear down the HDF5 library for the entire process.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+33
to
+37
| * The bundled HDF5 library is built without thread safety (Threadsafety: OFF in | ||
| * libhdf5.settings), so no two threads may execute HDF5 code concurrently. | ||
| * Geometry and trajectory loading both read the same .h5 from different threads, | ||
| * so every public reader method serializes on this process-wide lock. | ||
| * The lock is recursive on all UE platforms, so public methods may call each other. |
sir306
added a commit
that referenced
this pull request
Aug 14, 2026
HDF5 thread-safety (real fix, equivalent to PR #13 re-pathed to the relocated MobiusDataImporter plugin): - Add a process-wide recursive FCriticalSection guarding every public FHdf5SimulationReader method (OpenFile, CloseFile, DetectFormat, and the nine Read* methods). The bundled HDF5 is built Threadsafety: OFF, so geometry + trajectory loaders on separate threads must serialize. - Remove all four H5close() calls. H5close() is a process-wide library teardown, not a per-file close; one thread calling it demolished the library under another mid-operation. H5Fclose(FileId) still releases each file; the library now lives for the process lifetime. Font GC root (WIP, does NOT resolve the reported crash yet): - AddToRoot the shared Font_Inter at its Slate load sites (SFieldAndTitleText::SetFieldFontFace, UIThemeSubsystem::GetInterFont) so a file-switch GC cannot collect it. - The SIGSEGV at 0xdd... in FSlateFontInfo::GetCompositeFont during UStatisticSubsystem::ResetForFileSwitch still reproduces on consecutive .h5 loads. Now also reproduces on Windows; continuing the investigation there. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Loading an HDF5 simulation could crash the editor outright:
Cause
Two independent problems combine:
1.
H5close()is a process-wide shutdown, not a per-file close. It was called in three places —CloseFile(),OpenFile()'s error path, andDetectFormat(). Any reader finishing its work therefore demolished the HDF5 library for every other reader. In the crash above, one thread ranH5close()while the trajectory worker was still insideH5_init_library(), so the property-class table it was walking was freed underneath it.2. The bundled HDF5 is not thread-safe.
Plugins/Hdf5DataPlugin/Source/ThirdParty/hdf5-2.0.0/install/lib/libhdf5.settingsreportsThreadsafety: OFF, and the superbuild passes noHDF5_ENABLE_THREADSAFE. Two threads executing HDF5 code at once is undefined behaviour even when they are reading different files — and the geometry loader (FAssimpMeshLoaderRunnable) and the trajectory loader (FProcessSimulationDataRunnable) each open.h5files on their own threads.Change
OpenFile,CloseFile,DetectFormat, and the nineRead*methods. Recursive becauseOpenFilecallsCloseFileinternally.H5close()calls removed. The library now lives for the lifetime of the process, which is the normal way to use HDF5;H5Fclose(FileId)still releases each file.Known trade-off: a geometry load and a trajectory load of the same file now queue rather than interleave. Ordered and slower beats concurrent and crashing. The alternative — rebuilding HDF5 with
HDF5_ENABLE_THREADSAFE=ON— is a larger change and may conflict withHDF5_BUILD_HL_LIB=ON; worth considering separately if the serialization ever shows up as a bottleneck.Verification
macOS, UE 5.5.4, 170 MB Juelich file (7.17M trajectory records, 516 entities): crashed reliably before, loads cleanly after, with geometry and trajectories read from the same file on different threads.
Note
Hdf5DataExampleTest.cppstill callsH5open()/H5close()directly. It is automation-test-only code and left untouched here to keep the change minimal, but running that test alongside a loaded simulation would reintroduce the same teardown hazard.