Переглянути джерело

Fix resource reloading not releasing previous resource and add reload support to sound resources

Daniele Bartolini 12 роки тому
батько
коміт
ac356ff3de
1 змінених файлів з 13 додано та 1 видалено
  1. 13 1
      engine/Device.cpp

+ 13 - 1
engine/Device.cpp

@@ -475,7 +475,6 @@ void Device::reload(const char* type, const char* name)
 		filename += '.';
 		filename += type;
 
-		const void* old_res = m_resource_manager->lookup(type, name);
 
 		if (!m_bundle_compiler->compile(m_bundle_dir, m_source_dir, filename.c_str()))
 		{
@@ -483,6 +482,10 @@ void Device::reload(const char* type, const char* name)
 			return;
 		}
 
+		ResourceId old_res_id = m_resource_manager->resource_id(type, name);
+		const void* old_res = m_resource_manager->data(old_res_id);
+		m_resource_manager->unload(old_res_id, true);
+
 		ResourceId res_id = m_resource_manager->load(type, name);
 		m_resource_manager->flush();
 		const void* new_res = m_resource_manager->data(res_id);
@@ -501,6 +504,15 @@ void Device::reload(const char* type, const char* name)
 				}
 				break;
 			}
+			case SOUND_TYPE:
+			{
+				Log::d("Reloading sound: %s", name);
+				for (uint32_t i = 0; i < m_world_manager->worlds().size(); i++)
+				{
+					m_world_manager->worlds()[i]->sound_world()->reload_sounds((SoundResource*) old_res, (SoundResource*) new_res);
+				}
+				break;
+			}
 			default:
 			{
 				CE_ASSERT(false, "Oops, unknown resource type: %s", type);