Enhance thread safety of loaders and importers

This commit is contained in:
Pedro J. Estébanez 2023-01-19 13:45:04 +01:00
parent 7537a0521f
commit 45d0b38076
5 changed files with 7 additions and 10 deletions

View File

@ -218,18 +218,20 @@ public:
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) {

View File

@ -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);

View File

@ -505,6 +505,7 @@ private:
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>();
}

View File

@ -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]);
}
}

View File

@ -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();
}
}