You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
The bug was caused by a second attempt to submit the same job at a higher priority, in between the time the job was created and added to the pending list. The job ends up getting linked a second time by the creation logic, corrupting the linked lists. The fix is simply to keep write lock active when submitting new jobs until the end of the function where the job is added to the pending list, so the addition of the job to the pending list completes before any other submits can occur. Keeping the write lock active is more efficient than reacquiring a read lock anyway (there's no processing between the locks, and a cheap linked list insertion beyond that), so this actually saves performance. For further potential safety, the other place where a read lock is used (forcing a job to run locally that was previously assigned to an external worker) was upgraded to write lock. This is a rare case, which also doesn't happen during cooks. Besides the fix, some changes were made to make the code overall less fragile for future maintenance. LinkJobWithPriority / UnlinkJobWithPriority now exclusively handle setting PendingPriority on the job, rather than setting it externally. PendingPriority should match the pending list the job is in (or be EShaderCompileJobPriority::None if not in a pending list), and NumPendingJobs should match the count of items in a pending linked list. With this change, all three are updated in tandem in those functions. FShaderJobCache::GetPendingJobs was changed to just call UnlinkJobWithPriority as well (updating NumPendingJobs in the regular way), rather than doing its own separate count adjustment outside the loop. Asserts will now detect linking of jobs that were already linked, unlinking jobs that are not linked, or jobs mysteriously in the wrong pending queue, so we can hopefully detect bugs earlier when an invalid list operation occurs, rather than later when the pending queue is processed. #rnx #rb jason.nadro dan.elksnitis [CL 27270105 by jason hoerner in ue5-main branch]