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.
The issue:
I have encountered an occasional crash when importing large glTF models at runtime.
After looking into the issue, the crash seemed to be caused by multiple threads incrementing/decrementing the SharedReferenceCount of a TSharedPtr pointing to a FJsonValueArray (usually the "bufferViews" array). This operation is not atomic by default.
The fix:
Since TSharedPtr is not thread-safe by default, we have to change the Mode-parameter of MakeShared when creating the shared pointers. However, since MakeShared is called by Unreal's JsonSerializer (which uses the default Mode) we can't control how each shared pointer is constructed and will instead need to change the default shared pointer Mode for the whole plugin.
For reference, see the implementation of MakeShared in SharedPointer.h. The Mode is set to ESPMode::Fast by default, which will be thread safe only if FORCE_THREADSAFE_SHAREDPTRS (or PLATFORM_WEAKLY_CONSISTENT_MEMORY) is set to 1.