Try cleaning up textures when unloading tracks. Crashes at this time, more debugging is required

This commit is contained in:
auria.mg 2016-12-26 22:33:54 -05:00
parent 46e7b5ac77
commit 943373ea8e
5 changed files with 33 additions and 10 deletions

View File

@ -521,7 +521,6 @@ void Material::install(bool is_full_path, bool complain_if_not_found)
video::ITexture* tex = irr_driver->applyMask(m_texture, m_mask);
if (tex)
{
// TODO
irr_driver->removeTexture(m_texture);
m_texture = tex;
}
@ -537,15 +536,7 @@ void Material::install(bool is_full_path, bool complain_if_not_found)
//-----------------------------------------------------------------------------
Material::~Material()
{
if (m_texture != NULL)
{
m_texture->drop();
if (m_texture->getReferenceCount() == 1)
{
irr_driver->removeTexture(m_texture);
m_texture = NULL;
}
}
unloadTexture();
// If a special sfx is installed (that isn't part of stk itself), the
// entry needs to be removed from the sfx_manager's mapping, since other
@ -556,6 +547,22 @@ Material::~Material()
}
} // ~Material
//-----------------------------------------------------------------------------
void Material::unloadTexture()
{
if (m_texture != NULL)
{
m_texture->drop();
if (m_texture->getReferenceCount() == 1)
{
irr_driver->removeTexture(m_texture);
}
m_texture = NULL;
m_installed = false;
}
}
//-----------------------------------------------------------------------------
/** Initialise the data structures for a custom sfx to be played when a
* kart is driving on that particular material.

View File

@ -283,6 +283,8 @@ public:
bool load_texture = true);
~Material ();
void unloadTexture();
void setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) const;
void setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* mb);
void adjustForFog(scene::ISceneNode* parent, video::SMaterial *m,

View File

@ -383,6 +383,16 @@ void MaterialManager::makeMaterialsPermanent()
m_shared_material_index = (int) m_materials.size();
} // makeMaterialsPermanent
// ----------------------------------------------------------------------------
void MaterialManager::unloadAllTextures()
{
for (int i = 0; i < m_shared_material_index; i++)
{
m_materials[i]->unloadTexture();
}
}
// ----------------------------------------------------------------------------
bool MaterialManager::hasMaterial(const std::string& fname)
{

View File

@ -83,6 +83,8 @@ public:
void makeMaterialsPermanent();
bool hasMaterial(const std::string& fname);
void unloadAllTextures();
Material* getLatestMaterial() { return m_materials[m_materials.size()-1]; }
}; // MaterialManager

View File

@ -28,6 +28,7 @@
#include "graphics/camera.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/render_info.hpp"
#include "io/file_manager.hpp"
#include "input/device_manager.hpp"
@ -430,6 +431,7 @@ Controller* World::loadAIController(AbstractKart *kart)
//-----------------------------------------------------------------------------
World::~World()
{
material_manager->unloadAllTextures();
RewindManager::destroy();
irr_driver->onUnloadWorld();