You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-22 15:06:45 +00:00
Avoid sync issues in materials with scheduled shader updates
This commit is contained in:
@@ -82,6 +82,23 @@ void Material::_validate_property(PropertyInfo &p_property) const {
|
||||
}
|
||||
}
|
||||
|
||||
void Material::_mark_initialized(const Callable &p_queue_shader_change_callable) {
|
||||
// If this is happening as part of resource loading, it is not safe to queue the update
|
||||
// as an addition to the dirty list, unless the load is happening on the main thread.
|
||||
if (ResourceLoader::is_within_load() && Thread::get_caller_id() != Thread::get_main_id()) {
|
||||
DEV_ASSERT(init_state != INIT_STATE_READY);
|
||||
if (init_state == INIT_STATE_UNINITIALIZED) { // Prevent queueing twice.
|
||||
// Queue an individual update of this material (the ResourceLoader knows how to handle deferred calls safely).
|
||||
p_queue_shader_change_callable.call_deferred();
|
||||
init_state = INIT_STATE_INITIALIZING;
|
||||
}
|
||||
} else {
|
||||
// Straightforward conditions.
|
||||
init_state = INIT_STATE_READY;
|
||||
p_queue_shader_change_callable.callv(Array());
|
||||
}
|
||||
}
|
||||
|
||||
void Material::inspect_native_shader_code() {
|
||||
SceneTree *st = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
|
||||
RID shader = get_shader_rid();
|
||||
@@ -1485,7 +1502,7 @@ void BaseMaterial3D::flush_changes() {
|
||||
void BaseMaterial3D::_queue_shader_change() {
|
||||
MutexLock lock(material_mutex);
|
||||
|
||||
if (is_initialized && !element.in_list()) {
|
||||
if (_is_initialized() && !element.in_list()) {
|
||||
dirty_materials->add(&element);
|
||||
}
|
||||
}
|
||||
@@ -3028,8 +3045,7 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) :
|
||||
flags[FLAG_ALBEDO_TEXTURE_MSDF] = false;
|
||||
flags[FLAG_USE_TEXTURE_REPEAT] = true;
|
||||
|
||||
is_initialized = true;
|
||||
_queue_shader_change();
|
||||
_mark_initialized(callable_mp(this, &BaseMaterial3D::_queue_shader_change));
|
||||
}
|
||||
|
||||
BaseMaterial3D::~BaseMaterial3D() {
|
||||
|
||||
Reference in New Issue
Block a user