mirror of
https://github.com/Relintai/props.git
synced 2025-02-10 16:30:06 +01:00
Only call initial_setup_default on the main thread, and document that shader duplication can crash if done from a different thread. Removed the material mutex from the prop cache as it's not needed anymore.
This commit is contained in:
parent
4be30142fb
commit
2568178b42
@ -282,6 +282,8 @@ void PropMaterialCache::refresh_rects() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PropMaterialCache::initial_setup_default() {
|
void PropMaterialCache::initial_setup_default() {
|
||||||
|
//Note: call only on the main thread! Shader->duplicate() can crash if done from an another thread!
|
||||||
|
|
||||||
PropCache *pc = PropCache::get_singleton();
|
PropCache *pc = PropCache::get_singleton();
|
||||||
|
|
||||||
pc->ensure_materials_loaded();
|
pc->ensure_materials_loaded();
|
||||||
|
@ -533,6 +533,21 @@ void PropInstanceMerger::_build() {
|
|||||||
|
|
||||||
Ref<PropMaterialCache> cache = PropCache::get_singleton()->material_cache_get(_prop_data);
|
Ref<PropMaterialCache> cache = PropCache::get_singleton()->material_cache_get(_prop_data);
|
||||||
|
|
||||||
|
if (!cache->get_initialized()) {
|
||||||
|
//lock it!
|
||||||
|
cache->mutex_lock();
|
||||||
|
|
||||||
|
//check again, this thread might have gotten here after an another one already did the initialization!
|
||||||
|
//this check might not be needed here
|
||||||
|
if (!cache->get_initialized()) {
|
||||||
|
//this will set up materials, and settings
|
||||||
|
//needs to be called from the main thread!
|
||||||
|
cache->initial_setup_default();
|
||||||
|
}
|
||||||
|
|
||||||
|
cache->mutex_unlock();
|
||||||
|
}
|
||||||
|
|
||||||
_job->set_material_cache(cache);
|
_job->set_material_cache(cache);
|
||||||
|
|
||||||
prop_preprocess(Transform(), _prop_data);
|
prop_preprocess(Transform(), _prop_data);
|
||||||
@ -588,7 +603,6 @@ void PropInstanceMerger::_prop_preprocess(Transform transform, const Ref<PropDat
|
|||||||
Ref<PropDataTiledWall> tiled_wall_data = e;
|
Ref<PropDataTiledWall> tiled_wall_data = e;
|
||||||
|
|
||||||
if (tiled_wall_data.is_valid()) {
|
if (tiled_wall_data.is_valid()) {
|
||||||
|
|
||||||
_job->add_tiled_wall(tiled_wall_data, t);
|
_job->add_tiled_wall(tiled_wall_data, t);
|
||||||
|
|
||||||
if (tiled_wall_data->get_collision()) {
|
if (tiled_wall_data->get_collision()) {
|
||||||
|
@ -267,7 +267,9 @@ void PropInstancePropJob::phase_setup_cache() {
|
|||||||
//check again, this thread might have gotten here after an another one already did the initialization!
|
//check again, this thread might have gotten here after an another one already did the initialization!
|
||||||
if (!_material_cache->get_initialized()) {
|
if (!_material_cache->get_initialized()) {
|
||||||
//this will set up materials, and settings
|
//this will set up materials, and settings
|
||||||
_material_cache->initial_setup_default();
|
//Can only be called from the main thread!
|
||||||
|
//Merger calls this
|
||||||
|
//_material_cache->initial_setup_default();
|
||||||
|
|
||||||
_material_cache->prop_add_textures(_prop_instace->get_prop_data());
|
_material_cache->prop_add_textures(_prop_instace->get_prop_data());
|
||||||
|
|
||||||
|
@ -170,13 +170,9 @@ void PropCache::materials_load() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PropCache::ensure_materials_loaded() {
|
void PropCache::ensure_materials_loaded() {
|
||||||
_material_mutex.lock();
|
|
||||||
|
|
||||||
if (_materials.size() != _material_paths.size()) {
|
if (_materials.size() != _material_paths.size()) {
|
||||||
materials_load();
|
materials_load();
|
||||||
}
|
}
|
||||||
|
|
||||||
_material_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Variant> PropCache::materials_get() {
|
Vector<Variant> PropCache::materials_get() {
|
||||||
|
@ -122,8 +122,6 @@ protected:
|
|||||||
Mutex _tiled_wall_material_cache_mutex;
|
Mutex _tiled_wall_material_cache_mutex;
|
||||||
Mutex _custom_keyed_material_cache_mutex;
|
Mutex _custom_keyed_material_cache_mutex;
|
||||||
|
|
||||||
Mutex _material_mutex;
|
|
||||||
|
|
||||||
#ifdef TEXTURE_PACKER_PRESENT
|
#ifdef TEXTURE_PACKER_PRESENT
|
||||||
int _texture_flags;
|
int _texture_flags;
|
||||||
int _max_atlas_size;
|
int _max_atlas_size;
|
||||||
|
@ -155,6 +155,7 @@ void TiledWall::refresh() {
|
|||||||
|
|
||||||
//An anouther thread could have initialized it before wo got the mutex!
|
//An anouther thread could have initialized it before wo got the mutex!
|
||||||
if (!_cache->get_initialized()) {
|
if (!_cache->get_initialized()) {
|
||||||
|
//can only be called from the main thread!
|
||||||
_cache->initial_setup_default();
|
_cache->initial_setup_default();
|
||||||
|
|
||||||
_data->setup_cache(_cache);
|
_data->setup_cache(_cache);
|
||||||
|
Loading…
Reference in New Issue
Block a user