forked from bartvdbraak/blender
fix read outside buffer range KX_ObstacleSimulationTOI_rays::sampleRVO,
Was using 3d vectors for 2d operations, passing float[2] to args that use MT_Vector3 was reading the 3rd value of a 2d array
This commit is contained in:
parent
c0b73fa1b0
commit
fee152d0ec
@ -42,8 +42,12 @@ namespace
|
|||||||
inline void vset(float v[2], float x, float y) { v[0] = x; v[1] = y; }
|
inline void vset(float v[2], float x, float y) { v[0] = x; v[1] = y; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sweepCircleCircle(const MT_Vector3& pos0, const MT_Scalar r0, const MT_Vector2& v,
|
/* grr, seems moto provides no nice way to do this */
|
||||||
const MT_Vector3& pos1, const MT_Scalar r1,
|
#define MT_3D_AS_2D(v) MT_Vector2((v)[0], (v)[1])
|
||||||
|
|
||||||
|
static int sweepCircleCircle(
|
||||||
|
const MT_Vector2 &pos0, const MT_Scalar r0, const MT_Vector2 &v,
|
||||||
|
const MT_Vector2 &pos1, const MT_Scalar r1,
|
||||||
float& tmin, float& tmax)
|
float& tmin, float& tmax)
|
||||||
{
|
{
|
||||||
static const float EPS = 0.0001f;
|
static const float EPS = 0.0001f;
|
||||||
@ -64,8 +68,9 @@ static int sweepCircleCircle(const MT_Vector3& pos0, const MT_Scalar r0, const M
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sweepCircleSegment(const MT_Vector3& pos0, const MT_Scalar r0, const MT_Vector2& v,
|
static int sweepCircleSegment(
|
||||||
const MT_Vector3& pa, const MT_Vector3& pb, const MT_Scalar sr,
|
const MT_Vector2 &pos0, const MT_Scalar r0, const MT_Vector2 &v,
|
||||||
|
const MT_Vector2& pa, const MT_Vector2 &pb, const MT_Scalar sr,
|
||||||
float& tmin, float &tmax)
|
float& tmin, float &tmax)
|
||||||
{
|
{
|
||||||
// equation parameters
|
// equation parameters
|
||||||
@ -484,10 +489,12 @@ void KX_ObstacleSimulationTOI_rays::sampleRVO(KX_Obstacle* activeObst, KX_NavMes
|
|||||||
vab = 2*svel - vel - ob->vel;
|
vab = 2*svel - vel - ob->vel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sweepCircleCircle(activeObst->m_pos, activeObst->m_rad,
|
if (!sweepCircleCircle(MT_3D_AS_2D(activeObst->m_pos), activeObst->m_rad,
|
||||||
vab, ob->m_pos, ob->m_rad, htmin, htmax))
|
vab, MT_3D_AS_2D(ob->m_pos), ob->m_rad, htmin, htmax))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (ob->m_shape == KX_OBSTACLE_SEGMENT)
|
else if (ob->m_shape == KX_OBSTACLE_SEGMENT)
|
||||||
{
|
{
|
||||||
MT_Point3 p1 = ob->m_pos;
|
MT_Point3 p1 = ob->m_pos;
|
||||||
@ -499,10 +506,13 @@ void KX_ObstacleSimulationTOI_rays::sampleRVO(KX_Obstacle* activeObst, KX_NavMes
|
|||||||
p1 = navmeshobj->TransformToWorldCoords(p1);
|
p1 = navmeshobj->TransformToWorldCoords(p1);
|
||||||
p2 = navmeshobj->TransformToWorldCoords(p2);
|
p2 = navmeshobj->TransformToWorldCoords(p2);
|
||||||
}
|
}
|
||||||
if (!sweepCircleSegment(activeObst->m_pos, activeObst->m_rad, svel,
|
|
||||||
p1, p2, ob->m_rad, htmin, htmax))
|
if (!sweepCircleSegment(MT_3D_AS_2D(activeObst->m_pos), activeObst->m_rad, svel,
|
||||||
|
MT_3D_AS_2D(p1), MT_3D_AS_2D(p2), ob->m_rad, htmin, htmax))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -644,9 +654,11 @@ static void processSamples(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavM
|
|||||||
dot_v2v2(np, vab)) * 2.0f, 0.0f, 1.0f);
|
dot_v2v2(np, vab)) * 2.0f, 0.0f, 1.0f);
|
||||||
nside++;
|
nside++;
|
||||||
|
|
||||||
if (!sweepCircleCircle(activeObst->m_pos, activeObst->m_rad, vab, ob->m_pos, ob->m_rad,
|
if (!sweepCircleCircle(MT_3D_AS_2D(activeObst->m_pos), activeObst->m_rad,
|
||||||
htmin, htmax))
|
vab, MT_3D_AS_2D(ob->m_pos), ob->m_rad, htmin, htmax))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle overlapping obstacles.
|
// Handle overlapping obstacles.
|
||||||
if (htmin < 0.0f && htmax > 0.0f)
|
if (htmin < 0.0f && htmax > 0.0f)
|
||||||
|
Loading…
Reference in New Issue
Block a user