don't crash if the maximum number of pairs is exceeded, but report an error using b3Error

This commit is contained in:
erwin coumans 2013-06-17 13:23:41 -07:00
parent f73d11d896
commit 31282ab85e
5 changed files with 17 additions and 10 deletions

View File

@ -397,7 +397,7 @@ void ParticleDemo::clientMoveAndDisplay()
cl_mem pairsGPU = 0;
{
m_data->m_broadphaseGPU->calculateOverlappingPairs();
m_data->m_broadphaseGPU->calculateOverlappingPairs(64*numParticles);
pairsGPU = m_data->m_broadphaseGPU->getOverlappingPairBuffer();
numPairsGPU = m_data->m_broadphaseGPU->getNumOverlap();
}

View File

@ -308,7 +308,7 @@ void PairBench::clientMoveAndDisplay()
}
{
B3_PROFILE("calculateOverlappingPairs");
m_data->m_broadphaseGPU->calculateOverlappingPairs();
m_data->m_broadphaseGPU->calculateOverlappingPairs(64*numObjects);
//int numPairs = m_data->m_broadphaseGPU->getNumOverlap();
//printf("numPairs = %d\n", numPairs);
}

View File

@ -155,7 +155,7 @@ void b3GpuSapBroadphase::calculateOverlappingPairsHostIncremental3Sap()
}
void b3GpuSapBroadphase::calculateOverlappingPairsHost()
void b3GpuSapBroadphase::calculateOverlappingPairsHost(int maxPairs)
{
//test
//if (m_currentBuffer>=0)
@ -236,6 +236,10 @@ void b3GpuSapBroadphase::calculateOverlappingPairsHost()
}
}
if (hostPairs.size() > maxPairs)
{
hostPairs.resize(maxPairs);
}
if (hostPairs.size())
{
@ -262,7 +266,7 @@ void b3GpuSapBroadphase::reset()
}
void b3GpuSapBroadphase::calculateOverlappingPairs()
void b3GpuSapBroadphase::calculateOverlappingPairs(int maxPairs)
{
int axis = 0;//todo on GPU for now hardcode
@ -398,8 +402,6 @@ void b3GpuSapBroadphase::calculateOverlappingPairs()
}
int maxPairsPerBody = 64;
int maxPairs = maxPairsPerBody * numSmallAabbs;//todo
m_overlappingPairs.resize(maxPairs);
b3OpenCLArray<int> pairCount(m_context, m_queue);
@ -423,8 +425,10 @@ void b3GpuSapBroadphase::calculateOverlappingPairs()
numPairs = pairCount.at(0);
if (numPairs >maxPairs)
{
b3Error("Error running out of pairs: numPairs = %d, maxPairs = %d.\n", numPairs, maxPairs);
numPairs =maxPairs;
}
}
}
if (m_gpuSmallSortedAabbs.size())
@ -467,7 +471,10 @@ void b3GpuSapBroadphase::calculateOverlappingPairs()
numPairs = pairCount.at(0);
if (numPairs>maxPairs)
{
b3Error("Error running out of pairs: numPairs = %d, maxPairs = %d.\n", numPairs, maxPairs);
numPairs = maxPairs;
}
}
#else

View File

@ -49,8 +49,8 @@ class b3GpuSapBroadphase
b3GpuSapBroadphase(cl_context ctx,cl_device_id device, cl_command_queue q );
virtual ~b3GpuSapBroadphase();
void calculateOverlappingPairs();
void calculateOverlappingPairsHost();
void calculateOverlappingPairs(int maxPairs);
void calculateOverlappingPairsHost(int maxPairs);
void reset();

View File

@ -144,7 +144,7 @@ void b3GpuRigidBodyPipeline::stepSimulation(float deltaTime)
numPairs = m_data->m_broadphaseDbvt->getOverlappingPairCache()->getNumOverlappingPairs();
} else
{
m_data->m_broadphaseSap->calculateOverlappingPairs();
m_data->m_broadphaseSap->calculateOverlappingPairs(m_data->m_config.m_maxBroadphasePairs);
numPairs = m_data->m_broadphaseSap->getNumOverlap();
}
}