Fix memory leaks and uninitialized values of ShadowMatrices

This commit is contained in:
Benau 2016-10-10 13:01:18 +08:00
parent d39f5e487b
commit 8e2d7c5499
2 changed files with 32 additions and 18 deletions

View File

@ -126,15 +126,34 @@ ShadowMatrices::ShadowMatrices()
m_shadow_cam_nodes[1] = NULL;
m_shadow_cam_nodes[2] = NULL;
m_shadow_cam_nodes[3] = NULL;
m_rsm_map_available = false;
m_rsm_matrix_initialized = false;
} // 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)
{
m_sun_cam->setPosition(pos);
m_sun_cam->updateAbsolutePosition();
m_rsm_matrix_initialized = false;
} // addLight
// ----------------------------------------------------------------------------
@ -334,17 +353,6 @@ void ShadowMatrices::computeMatrixesAndCameras(scene::ICameraSceneNode *const ca
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[] =
{
ShadowMatrices::m_shadow_split[1],
@ -411,8 +419,16 @@ void ShadowMatrices::computeMatrixesAndCameras(scene::ICameraSceneNode *const ca
}
// 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 &&
trackbox.MinEdge.Y != trackbox.MaxEdge.Y &&
// Cover the case where sun_cam_view_matrix is null

View File

@ -61,6 +61,7 @@ private:
public:
ShadowMatrices();
~ShadowMatrices();
void computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode,
unsigned int width, unsigned int height);
@ -69,10 +70,7 @@ public:
void renderShadowsDebug();
// ------------------------------------------------------------------------
void resetShadowCamNodes()
{
memset(m_shadow_cam_nodes, 0, 4 * sizeof(void*));
} // resetShadowCamNodes
void resetShadowCamNodes();
// ------------------------------------------------------------------------
scene::ICameraSceneNode** getShadowCamNodes()
{