Skip to content

Commit

Permalink
Enhance thread safety of loaders and importers
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomShaper committed May 12, 2023
1 parent 7537a05 commit 45d0b38
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
6 changes: 4 additions & 2 deletions core/io/resource_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,20 @@ class ResourceLoader {
static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load = p_timestamp; }
static bool get_timestamp_on_load() { return timestamp_on_load; }

// Loaders can safely use this regardless which thread they are running on.
static void notify_load_error(const String &p_err) {
if (err_notify) {
err_notify(p_err);
callable_mp_static(err_notify).bind(p_err).call_deferred();
}
}
static void set_error_notify_func(ResourceLoadErrorNotify p_err_notify) {
err_notify = p_err_notify;
}

// Loaders can safely use this regardless which thread they are running on.
static void notify_dependency_error(const String &p_path, const String &p_dependency, const String &p_type) {
if (dep_err_notify) {
dep_err_notify(p_path, p_dependency, p_type);
callable_mp_static(dep_err_notify).bind(p_path, p_dependency, p_type).call_deferred();
}
}
static void set_dependency_error_notify_func(DependencyErrorNotify p_err_notify) {
Expand Down
1 change: 1 addition & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4115,6 +4115,7 @@ void EditorNode::notify_all_debug_sessions_exited() {
}

void EditorNode::add_io_error(const String &p_error) {
DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
singleton->load_errors->add_image(singleton->gui_base->get_theme_icon(SNAME("Error"), SNAME("EditorIcons")));
singleton->load_errors->add_text(p_error + "\n");
singleton->load_error_dialog->attach_and_popup_centered_ratio(0.5);
Expand Down
1 change: 1 addition & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ class EditorNode : public Node {
static Vector<EditorNodeInitCallback> _init_callbacks;

static void _dependency_error_report(const String &p_path, const String &p_dep, const String &p_type) {
DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
if (!singleton->dependency_errors.has(p_path)) {
singleton->dependency_errors[p_path] = HashSet<String>();
}
Expand Down
7 changes: 0 additions & 7 deletions editor/import/editor_import_collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1782,15 +1782,8 @@ Node *EditorSceneFormatImporterCollada::import_scene(const String &p_path, uint3
ERR_FAIL_COND_V_MSG(err != OK, nullptr, "Cannot load scene from file '" + p_path + "'.");

if (state.missing_textures.size()) {
/*
for(int i=0;i<state.missing_textures.size();i++) {
EditorNode::add_io_error("Texture Not Found: "+state.missing_textures[i]);
}
*/

if (r_missing_deps) {
for (int i = 0; i < state.missing_textures.size(); i++) {
//EditorNode::add_io_error("Texture Not Found: "+state.missing_textures[i]);
r_missing_deps->push_back(state.missing_textures[i]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion editor/import/resource_importer_shader_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Error ResourceImporterShaderFile::import(const String &p_source_file, const Stri

if (err != OK) {
if (!ShaderFileEditor::singleton->is_visible_in_tree()) {
EditorNode::get_singleton()->add_io_error(vformat(TTR("Error importing GLSL shader file: '%s'. Open the file in the filesystem dock in order to see the reason."), p_source_file));
callable_mp_static(&EditorNode::add_io_error).bind(vformat(TTR("Error importing GLSL shader file: '%s'. Open the file in the filesystem dock in order to see the reason."), p_source_file)).call_deferred();
}
}

Expand Down

0 comments on commit 45d0b38

Please sign in to comment.