Merge pull request #1142 from klusark/mat

GRIM: Fix deleting material when it is still needed
This commit is contained in:
Paweł Kołodziejski 2014-12-30 07:08:31 +01:00
commit 3c2203e8c6
2 changed files with 3 additions and 1 deletions

View File

@ -50,6 +50,7 @@ void MaterialComponent::init() {
for (int i = 0; i < model->_numMaterials; ++i) {
if (_name.compareToIgnoreCase(model->_materials[i]->getFilename()) == 0) {
_mat = model->_materials[i];
_mat->reference();
return;
}
}

View File

@ -90,7 +90,7 @@ Model::Model(const Common::String &filename, Common::SeekableReadStream *data, C
Model::~Model() {
for (int i = 0; i < _numMaterials; ++i) {
if (!_materialsShared[i]) {
delete _materials[i];
_materials[i]->dereference();
}
}
delete[] _materials;
@ -247,6 +247,7 @@ void Model::loadMaterial(int index, CMap *cmap) {
_materials[index] = mat;
} else {
_materials[index] = g_resourceloader->loadMaterial(_materialNames[index], cmap, false);
_materials[index]->reference();
}
_materialsShared[index] = false;
}