diff --git a/WickedEngine/emittedparticle_kickoffSortCS.hlsl b/WickedEngine/emittedparticle_kickoffSortCS.hlsl index e501b39bb..e76c7902b 100644 --- a/WickedEngine/emittedparticle_kickoffSortCS.hlsl +++ b/WickedEngine/emittedparticle_kickoffSortCS.hlsl @@ -14,7 +14,7 @@ void main( uint3 DTid : SV_DispatchThreadID ) counterBuffer[0].aliveCount_afterSimulation = aliveCount_afterSimulation; // calculate threadcount: - uint threadCount = ((aliveCount_afterSimulation - 1) >> 9) + 1; + uint threadCount = ((max(1, aliveCount_afterSimulation) - 1) >> 9) + 1; // and prepare to dispatch the sort for the alive simulated particles: indirectBuffers.Store3(ARGUMENTBUFFER_OFFSET_DISPATCHSORT, uint3(threadCount, 1, 1)); diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index 0500afd6a..abb5e7a57 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -212,6 +212,7 @@ void wiEmittedParticle::CreateSelfBuffers() counters.aliveCount = 0; counters.deadCount = MAX_PARTICLES; counters.realEmitCount = 0; + counters.aliveCount_afterSimulation = 0; data.pSysMem = &counters; bd.ByteWidth = sizeof(counters); @@ -394,7 +395,10 @@ void wiEmittedParticle::UpdateRenderData(GRAPHICSTHREAD threadID) unsigned int numThreadGroups = ((MAX_PARTICLES - 1) >> 9) + 1; - if (numThreadGroups>1) bDone = false; + if (numThreadGroups > 1) + { + bDone = false; + } // sort all buffers of size 512 (and presort bigger ones) device->BindComputePSO(&CPSO_sort, threadID);