Skip to content

Fix race condition while loading lights#53

Open
caseif wants to merge 1 commit intoOpenAWE-Project:masterfrom
caseif:fix/lights-race-condition
Open

Fix race condition while loading lights#53
caseif wants to merge 1 commit intoOpenAWE-Project:masterfrom
caseif:fix/lights-race-condition

Conversation

@caseif
Copy link
Contributor

@caseif caseif commented Nov 5, 2024

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.

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.
@caseif caseif force-pushed the fix/lights-race-condition branch from cff275c to 361c5bc Compare November 7, 2024 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant