From c1f5233217f35d59849fc920f4147f9a8b3f0885 Mon Sep 17 00:00:00 2001 From: Ibrahn Sahir Date: Wed, 21 Nov 2018 15:48:05 +0000 Subject: [PATCH] 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. --- scene/2d/canvas_item.cpp | 15 ++++++++++----- scene/2d/canvas_item.h | 2 +- scene/resources/material.cpp | 15 ++++++++++----- scene/resources/material.h | 2 +- scene/resources/particles_material.cpp | 15 ++++++++++----- scene/resources/particles_material.h | 2 +- 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 0ea2e85dfa5..698bbf41ead 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -42,7 +42,7 @@ #include "servers/visual_server.h" Mutex *CanvasItemMaterial::material_mutex = NULL; -SelfList::List CanvasItemMaterial::dirty_materials; +SelfList::List *CanvasItemMaterial::dirty_materials = NULL; Map CanvasItemMaterial::shader_map; CanvasItemMaterial::ShaderNames *CanvasItemMaterial::shader_names = NULL; @@ -52,6 +52,8 @@ void CanvasItemMaterial::init_shaders() { material_mutex = Mutex::create(); #endif + dirty_materials = memnew(SelfList::List); + shader_names = memnew(ShaderNames); shader_names->particles_anim_h_frames = "particles_anim_h_frames"; @@ -61,6 +63,9 @@ void CanvasItemMaterial::init_shaders() { void CanvasItemMaterial::finish_shaders() { + memdelete(dirty_materials); + dirty_materials = NULL; + #ifndef NO_THREADS memdelete(material_mutex); #endif @@ -68,7 +73,7 @@ void CanvasItemMaterial::finish_shaders() { void CanvasItemMaterial::_update_shader() { - dirty_materials.remove(&element); + dirty_materials->remove(&element); MaterialKey mk = _compute_key(); if (mk.key == current_key.key) @@ -157,9 +162,9 @@ void CanvasItemMaterial::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) @@ -172,7 +177,7 @@ void CanvasItemMaterial::_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/2d/canvas_item.h b/scene/2d/canvas_item.h index 9fe7cb1e00b..1a6016e6e10 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -109,7 +109,7 @@ private: } static Mutex *material_mutex; - static SelfList::List dirty_materials; + static SelfList::List *dirty_materials; SelfList element; void _update_shader(); diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 5327ed318ff..65ee242ff89 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -258,7 +258,7 @@ ShaderMaterial::~ShaderMaterial() { ///////////////////////////////// Mutex *SpatialMaterial::material_mutex = NULL; -SelfList::List SpatialMaterial::dirty_materials; +SelfList::List *SpatialMaterial::dirty_materials = NULL; Map 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::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 54fceaddc12..921f3baeaa6 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -360,7 +360,7 @@ private: }; static Mutex *material_mutex; - static SelfList::List dirty_materials; + static SelfList::List *dirty_materials; static ShaderNames *shader_names; SelfList element; diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp index dae01e8d965..92c185712ab 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::List ParticlesMaterial::dirty_materials; +SelfList::List *ParticlesMaterial::dirty_materials = NULL; Map 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::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 06ebb3c4dca..20b505532e7 100644 --- a/scene/resources/particles_material.h +++ b/scene/resources/particles_material.h @@ -126,7 +126,7 @@ private: } static Mutex *material_mutex; - static SelfList::List dirty_materials; + static SelfList::List *dirty_materials; struct ShaderNames { StringName spread;