summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
authorIbrahn Sahir <ibrahn.sahir@gmail.com>2018-11-21 15:48:05 +0000
committerIbrahn Sahir <ibrahn.sahir@gmail.com>2018-11-21 15:51:50 +0000
commitc1f5233217f35d59849fc920f4147f9a8b3f0885 (patch)
treeb631e42da562f3a8236bf6610629724967f94c42 /scene/resources
parent03bd4d28a541c626e9ad70e4520a17b6f45e900a (diff)
Moved dirty material lists from static to lifetime controlled by main.
As with 7d82bed4f4cac8f5227d935c0496290e24eb48c8, The list is now destroyed before the OS object, so can print errors if there are unfreed materials.
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/material.cpp15
-rw-r--r--scene/resources/material.h2
-rw-r--r--scene/resources/particles_material.cpp15
-rw-r--r--scene/resources/particles_material.h2
4 files changed, 22 insertions, 12 deletions
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 5327ed318f..65ee242ff8 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -258,7 +258,7 @@ ShaderMaterial::~ShaderMaterial() {
/////////////////////////////////
Mutex *SpatialMaterial::material_mutex = NULL;
-SelfList<SpatialMaterial>::List SpatialMaterial::dirty_materials;
+SelfList<SpatialMaterial>::List *SpatialMaterial::dirty_materials = NULL;
Map<SpatialMaterial::MaterialKey, SpatialMaterial::ShaderData> SpatialMaterial::shader_map;
SpatialMaterial::ShaderNames *SpatialMaterial::shader_names = NULL;
@@ -268,6 +268,8 @@ void SpatialMaterial::init_shaders() {
material_mutex = Mutex::create();
#endif
+ dirty_materials = memnew(SelfList<SpatialMaterial>::List);
+
shader_names = memnew(ShaderNames);
shader_names->albedo = "albedo";
@@ -348,12 +350,15 @@ void SpatialMaterial::finish_shaders() {
memdelete(material_mutex);
#endif
+ memdelete(dirty_materials);
+ dirty_materials = NULL;
+
memdelete(shader_names);
}
void SpatialMaterial::_update_shader() {
- dirty_materials.remove(&element);
+ dirty_materials->remove(&element);
MaterialKey mk = _compute_key();
if (mk.key == current_key.key)
@@ -1002,9 +1007,9 @@ void SpatialMaterial::flush_changes() {
if (material_mutex)
material_mutex->lock();
- while (dirty_materials.first()) {
+ while (dirty_materials->first()) {
- dirty_materials.first()->self()->_update_shader();
+ dirty_materials->first()->self()->_update_shader();
}
if (material_mutex)
@@ -1017,7 +1022,7 @@ void SpatialMaterial::_queue_shader_change() {
material_mutex->lock();
if (!element.in_list()) {
- dirty_materials.add(&element);
+ dirty_materials->add(&element);
}
if (material_mutex)
diff --git a/scene/resources/material.h b/scene/resources/material.h
index 54fceaddc1..921f3baeaa 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -360,7 +360,7 @@ private:
};
static Mutex *material_mutex;
- static SelfList<SpatialMaterial>::List dirty_materials;
+ static SelfList<SpatialMaterial>::List *dirty_materials;
static ShaderNames *shader_names;
SelfList<SpatialMaterial> element;
diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp
index dae01e8d96..92c185712a 100644
--- a/scene/resources/particles_material.cpp
+++ b/scene/resources/particles_material.cpp
@@ -31,7 +31,7 @@
#include "particles_material.h"
Mutex *ParticlesMaterial::material_mutex = NULL;
-SelfList<ParticlesMaterial>::List ParticlesMaterial::dirty_materials;
+SelfList<ParticlesMaterial>::List *ParticlesMaterial::dirty_materials = NULL;
Map<ParticlesMaterial::MaterialKey, ParticlesMaterial::ShaderData> ParticlesMaterial::shader_map;
ParticlesMaterial::ShaderNames *ParticlesMaterial::shader_names = NULL;
@@ -41,6 +41,8 @@ void ParticlesMaterial::init_shaders() {
material_mutex = Mutex::create();
#endif
+ dirty_materials = memnew(SelfList<ParticlesMaterial>::List);
+
shader_names = memnew(ShaderNames);
shader_names->spread = "spread";
@@ -106,12 +108,15 @@ void ParticlesMaterial::finish_shaders() {
memdelete(material_mutex);
#endif
+ memdelete(dirty_materials);
+ dirty_materials = NULL;
+
memdelete(shader_names);
}
void ParticlesMaterial::_update_shader() {
- dirty_materials.remove(&element);
+ dirty_materials->remove(&element);
MaterialKey mk = _compute_key();
if (mk.key == current_key.key)
@@ -584,9 +589,9 @@ void ParticlesMaterial::flush_changes() {
if (material_mutex)
material_mutex->lock();
- while (dirty_materials.first()) {
+ while (dirty_materials->first()) {
- dirty_materials.first()->self()->_update_shader();
+ dirty_materials->first()->self()->_update_shader();
}
if (material_mutex)
@@ -599,7 +604,7 @@ void ParticlesMaterial::_queue_shader_change() {
material_mutex->lock();
if (!element.in_list()) {
- dirty_materials.add(&element);
+ dirty_materials->add(&element);
}
if (material_mutex)
diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h
index 06ebb3c4dc..20b505532e 100644
--- a/scene/resources/particles_material.h
+++ b/scene/resources/particles_material.h
@@ -126,7 +126,7 @@ private:
}
static Mutex *material_mutex;
- static SelfList<ParticlesMaterial>::List dirty_materials;
+ static SelfList<ParticlesMaterial>::List *dirty_materials;
struct ShaderNames {
StringName spread;