Skip to content

Commit

Permalink
Free renderer properly when initialized partway
Browse files Browse the repository at this point in the history
The intialization of threading stuff can (theoretically) fail, so we
should handle it properly here.
  • Loading branch information
askmeaboutlo0m committed Aug 17, 2023
1 parent 09c3b1d commit 9140fb6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/drawdance/libengine/dpengine/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,17 @@ void DP_renderer_free(DP_Renderer *renderer)
{
if (renderer) {
int thread_count = renderer->thread_count;
DP_MUTEX_MUST_LOCK(renderer->queue_mutex);
DP_queue_clear(&renderer->blocking_queue, sizeof(DP_RenderJob),
dispose_blocking_job);
renderer->tile.queue_high.used = 0;
renderer->tile.queue_low.used = 0;
DP_SEMAPHORE_MUST_POST_N(renderer->queue_sem, thread_count);
DP_MUTEX_MUST_UNLOCK(renderer->queue_mutex);

for (int i = 0; i < thread_count; ++i) {
DP_thread_free_join(renderer->threads[i]);
if (renderer->queue_mutex && renderer->queue_sem) {
DP_MUTEX_MUST_LOCK(renderer->queue_mutex);
DP_queue_clear(&renderer->blocking_queue, sizeof(DP_RenderJob),
dispose_blocking_job);
renderer->tile.queue_high.used = 0;
renderer->tile.queue_low.used = 0;
DP_SEMAPHORE_MUST_POST_N(renderer->queue_sem, thread_count);
DP_MUTEX_MUST_UNLOCK(renderer->queue_mutex);
for (int i = 0; i < thread_count; ++i) {
DP_thread_free_join(renderer->threads[i]);
}
}
DP_semaphore_free(renderer->wait_done_sem);
DP_semaphore_free(renderer->wait_ready_sem);
Expand Down

0 comments on commit 9140fb6

Please sign in to comment.