Fix race condition while loading lights#53
Open
caseif wants to merge 1 commit intoOpenAWE-Project:masterfrom
Open
Fix race condition while loading lights#53caseif wants to merge 1 commit intoOpenAWE-Project:masterfrom
caseif wants to merge 1 commit intoOpenAWE-Project:masterfrom
Conversation
This fixes a race condition where the renderer could start reading the vector of lights at the same time that newly-loaded lights were being added to it, thus causing a segfault or other weird behavior. This is done by creating separate queues and a corresponding mutex for mutations to the list of lights in the renderer and flushing them before starting to draw the lights. Because this is basically just copying pointers, the actual timespan the mutex is held by the renderer is very low.
cff275c to
361c5bc
Compare
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.
This fixes a race condition where the renderer could start reading the vector of lights at the same time that newly-loaded lights were being added to it, thus causing a segfault or other weird behavior.
This is done by creating separate queues and a corresponding mutex for mutations to the list of lights in the renderer and flushing them before starting to draw the lights. Because this is basically just copying pointers, the actual timespan the mutex is held by the renderer is very low.
The fact that the worker thread acquires a new lock on the mutex every time it adds a new light is definitely not ideal since the lights are all loaded in one go, but this was the most sane implementation I came to while keeping some semblance of separation of concerns and not making the loader directly interface with the graphics system.