Solved crash when not viewing the sculpture view panel

The sculpture view panel was the one which handled the job system. If the panel was closed, jobs stopped being completed and the queue filled up.
This commit is contained in:
Peter Slattery 2020-02-29 15:07:56 -08:00
parent b103ede28c
commit 4224ba15fb
4 changed files with 31 additions and 13 deletions

View File

@ -405,10 +405,7 @@ UPDATE_AND_RENDER(UpdateAndRender)
Job->SendTo = Context.PlatformSendTo;
Job->DMXBuffers = DMXBuffers;
Context.GeneralWorkQueue->PushWorkOnQueue(
Context.GeneralWorkQueue,
SACNSendDMXBufferListJob,
Job);
Context.GeneralWorkQueue->PushWorkOnQueue(Context.GeneralWorkQueue, SACNSendDMXBufferListJob, Job, "SACN Send Data Job");
}break;
InvalidDefaultCase;
@ -430,6 +427,9 @@ UPDATE_AND_RENDER(UpdateAndRender)
}
}
Context.GeneralWorkQueue->DoQueueWorkUntilDone(Context.GeneralWorkQueue, 0);
Context.GeneralWorkQueue->ResetWorkQueue(Context.GeneralWorkQueue);
// Checking for overflows
{
DEBUG_TRACK_SCOPE(OverflowChecks);

View File

@ -180,7 +180,7 @@ typedef THREADED_WORK_PROC(threaded_work_proc);
typedef struct work_queue work_queue;
#define PUSH_WORK_ON_QUEUE(name) void name(work_queue* Queue, threaded_work_proc* WorkProc, void* Data)
#define PUSH_WORK_ON_QUEUE(name) void name(work_queue* Queue, threaded_work_proc* WorkProc, void* Data, char* JobName)
typedef PUSH_WORK_ON_QUEUE(push_work_on_queue);
#define DO_QUEUE_WORK_UNTIL_DONE(name) void name(work_queue* Queue, s32 ThreadID)
@ -193,6 +193,9 @@ struct worker_thread_job
{
void* Data;
threaded_work_proc* WorkProc;
#ifdef DEBUG
char* JobName;
#endif
};
struct work_queue
@ -203,7 +206,7 @@ struct work_queue
u32 volatile JobsCount;
u32 volatile NextJobIndex;
u32 volatile JobsCompleted;
worker_thread_job Jobs[256];
worker_thread_job* Jobs;
// Work Queue
push_work_on_queue* PushWorkOnQueue;

View File

@ -174,15 +174,10 @@ SculptureView_Render(panel Panel, rect PanelBounds, render_command_buffer* Rende
JobData->ModelViewMatrix = ModelViewMatrix;
JobData->LEDHalfWidth = LEDHalfWidth;
Context.GeneralWorkQueue->PushWorkOnQueue(
Context.GeneralWorkQueue,
DrawLEDsInBufferRangeJob,
JobData);
Context.GeneralWorkQueue->PushWorkOnQueue(Context.GeneralWorkQueue, DrawLEDsInBufferRangeJob, JobData, "Sculpture Draw LEDS");
}
}
Context.GeneralWorkQueue->DoQueueWorkUntilDone(Context.GeneralWorkQueue, 0);
Context.GeneralWorkQueue->ResetWorkQueue(Context.GeneralWorkQueue);
}
#define FOLDHAUS_PANEL_SCULPTURE_VIEW_H

View File

@ -46,11 +46,28 @@ struct worker_thread_info
PUSH_WORK_ON_QUEUE(Win32PushWorkOnQueue)
{
#ifdef DEBUG
// NOTE(Peter): Just prints out the names of all the pending jobs if we end up
// overflowing the buffer
if (Queue->JobsCount >= Queue->JobsMax)
{
string DebugString = MakeString((char*)malloc(256), 256);
for (u32 i = 0; i < Queue->JobsCount; i++)
{
PrintF(&DebugString, "%d %s\n", i, Queue->Jobs[i].JobName);
NullTerminate(&DebugString);
OutputDebugStringA(DebugString.Memory);
}
}
#endif
Assert(Queue->JobsCount < Queue->JobsMax);
worker_thread_job* Job = Queue->Jobs + Queue->JobsCount;
Job->WorkProc = WorkProc;
Job->Data = Data;
#ifdef DEBUG
Job->JobName = JobName;
#endif
// Complete Past Writes before Future Writes
_WriteBarrier();
@ -596,12 +613,15 @@ WinMain (
work_queue WorkQueue = {};
WorkQueue.SemaphoreHandle = CreateSemaphoreEx(0, 0, PLATFORM_THREAD_COUNT, 0, 0, SEMAPHORE_ALL_ACCESS);
WorkQueue.JobsMax = 256;
WorkQueue.JobsMax = 512;
WorkQueue.Jobs = (worker_thread_job*)Win32Alloc(sizeof(worker_thread_job) * WorkQueue.JobsMax);
WorkQueue.NextJobIndex = 0;
WorkQueue.PushWorkOnQueue = Win32PushWorkOnQueue;
WorkQueue.DoQueueWorkUntilDone = Win32DoQueueWorkUntilDone;
WorkQueue.ResetWorkQueue = ResetWorkQueue;
OutputDebugStringA("Hellooooo\n");
for (s32 i = 0; i < PLATFORM_THREAD_COUNT; i++)
{
// ID = 0 is reserved for this thread