OpenAWE icon indicating copy to clipboard operation
OpenAWE copied to clipboard

Fix race condition while loading lights

Open caseif opened this issue 1 year ago • 0 comments

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.

caseif avatar Nov 05 '24 02:11 caseif