Fix memory leaks and uninitialized values of ShadowMatrices
This commit is contained in:
parent
d39f5e487b
commit
8e2d7c5499
@ -126,15 +126,34 @@ ShadowMatrices::ShadowMatrices()
|
|||||||
m_shadow_cam_nodes[1] = NULL;
|
m_shadow_cam_nodes[1] = NULL;
|
||||||
m_shadow_cam_nodes[2] = NULL;
|
m_shadow_cam_nodes[2] = NULL;
|
||||||
m_shadow_cam_nodes[3] = NULL;
|
m_shadow_cam_nodes[3] = NULL;
|
||||||
|
m_rsm_map_available = false;
|
||||||
|
m_rsm_matrix_initialized = false;
|
||||||
} // ShadowMatrices
|
} // ShadowMatrices
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
ShadowMatrices::~ShadowMatrices()
|
||||||
|
{
|
||||||
|
resetShadowCamNodes();
|
||||||
|
m_sun_cam->drop();
|
||||||
|
} // ~ShadowMatrices
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
void ShadowMatrices::resetShadowCamNodes()
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (m_shadow_cam_nodes[i])
|
||||||
|
{
|
||||||
|
m_shadow_cam_nodes[i]->drop();
|
||||||
|
m_shadow_cam_nodes[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // resetShadowCamNodes
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void ShadowMatrices::addLight(const core::vector3df &pos)
|
void ShadowMatrices::addLight(const core::vector3df &pos)
|
||||||
{
|
{
|
||||||
m_sun_cam->setPosition(pos);
|
m_sun_cam->setPosition(pos);
|
||||||
m_sun_cam->updateAbsolutePosition();
|
m_sun_cam->updateAbsolutePosition();
|
||||||
|
|
||||||
m_rsm_matrix_initialized = false;
|
m_rsm_matrix_initialized = false;
|
||||||
|
|
||||||
} // addLight
|
} // addLight
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -334,17 +353,6 @@ void ShadowMatrices::computeMatrixesAndCameras(scene::ICameraSceneNode *const ca
|
|||||||
|
|
||||||
if (World::getWorld() && World::getWorld()->getTrack())
|
if (World::getWorld() && World::getWorld()->getTrack())
|
||||||
{
|
{
|
||||||
// Compute track extent
|
|
||||||
btVector3 btmin, btmax;
|
|
||||||
if (World::getWorld()->getTrack()->getPtrTriangleMesh())
|
|
||||||
{
|
|
||||||
World::getWorld()->getTrack()->getTriangleMesh().getCollisionShape()
|
|
||||||
.getAabb(btTransform::getIdentity(), btmin, btmax);
|
|
||||||
}
|
|
||||||
const Vec3 vmin = btmin, vmax = btmax;
|
|
||||||
core::aabbox3df trackbox(vmin.toIrrVector(), vmax.toIrrVector() -
|
|
||||||
core::vector3df(0, 30, 0));
|
|
||||||
|
|
||||||
float FarValues[] =
|
float FarValues[] =
|
||||||
{
|
{
|
||||||
ShadowMatrices::m_shadow_split[1],
|
ShadowMatrices::m_shadow_split[1],
|
||||||
@ -411,8 +419,16 @@ void ShadowMatrices::computeMatrixesAndCameras(scene::ICameraSceneNode *const ca
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rsm Matrix and camera
|
// Rsm Matrix and camera
|
||||||
if (!m_rsm_matrix_initialized)
|
if (!m_rsm_matrix_initialized &&
|
||||||
|
World::getWorld()->getTrack()->getPtrTriangleMesh())
|
||||||
{
|
{
|
||||||
|
// Compute track extent
|
||||||
|
Vec3 vmin, vmax;
|
||||||
|
World::getWorld()->getTrack()->getTriangleMesh().getCollisionShape()
|
||||||
|
.getAabb(btTransform::getIdentity(), vmin, vmax);
|
||||||
|
core::aabbox3df trackbox(vmin.toIrrVector(), vmax.toIrrVector() -
|
||||||
|
core::vector3df(0, 30, 0));
|
||||||
|
|
||||||
if (trackbox.MinEdge.X != trackbox.MaxEdge.X &&
|
if (trackbox.MinEdge.X != trackbox.MaxEdge.X &&
|
||||||
trackbox.MinEdge.Y != trackbox.MaxEdge.Y &&
|
trackbox.MinEdge.Y != trackbox.MaxEdge.Y &&
|
||||||
// Cover the case where sun_cam_view_matrix is null
|
// Cover the case where sun_cam_view_matrix is null
|
||||||
|
@ -61,6 +61,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
ShadowMatrices();
|
ShadowMatrices();
|
||||||
|
~ShadowMatrices();
|
||||||
|
|
||||||
void computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode,
|
void computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode,
|
||||||
unsigned int width, unsigned int height);
|
unsigned int width, unsigned int height);
|
||||||
@ -69,10 +70,7 @@ public:
|
|||||||
void renderShadowsDebug();
|
void renderShadowsDebug();
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void resetShadowCamNodes()
|
void resetShadowCamNodes();
|
||||||
{
|
|
||||||
memset(m_shadow_cam_nodes, 0, 4 * sizeof(void*));
|
|
||||||
} // resetShadowCamNodes
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
scene::ICameraSceneNode** getShadowCamNodes()
|
scene::ICameraSceneNode** getShadowCamNodes()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user