Skip to content

Commit 4861ab4

Browse files
committed
Use mutex to protect max_index in ImportThreadData
1 parent 80de898 commit 4861ab4

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

editor/editor_file_system.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,8 +2211,9 @@ void EditorFileSystem::reimport_file_with_custom_parameters(const String &p_file
22112211
}
22122212

22132213
void EditorFileSystem::_reimport_thread(uint32_t p_index, ImportThreadData *p_import_data) {
2214-
p_import_data->max_index = MAX(p_import_data->reimport_from + int(p_index), p_import_data->max_index);
2215-
_reimport_file(p_import_data->reimport_files[p_import_data->reimport_from + p_index].path);
2214+
int current_max = p_import_data->reimport_from + int(p_index);
2215+
p_import_data->max_index.exchange_if_greater(current_max);
2216+
_reimport_file(p_import_data->reimport_files[current_max].path);
22162217
}
22172218

22182219
void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
@@ -2288,15 +2289,15 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
22882289
importer->import_threaded_begin();
22892290

22902291
ImportThreadData tdata;
2291-
tdata.max_index = from;
2292+
tdata.max_index.set(from);
22922293
tdata.reimport_from = from;
22932294
tdata.reimport_files = reimport_files.ptr();
22942295

22952296
WorkerThreadPool::GroupID group_task = WorkerThreadPool::get_singleton()->add_template_group_task(this, &EditorFileSystem::_reimport_thread, &tdata, i - from + 1, -1, false, vformat(TTR("Import resources of type: %s"), reimport_files[from].importer));
22962297
int current_index = from - 1;
22972298
do {
2298-
if (current_index < tdata.max_index) {
2299-
current_index = tdata.max_index;
2299+
if (current_index < tdata.max_index.get()) {
2300+
current_index = tdata.max_index.get();
23002301
pr.step(reimport_files[current_index].path.get_file(), current_index);
23012302
}
23022303
OS::get_singleton()->delay_usec(1);

editor/editor_file_system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class EditorFileSystem : public Node {
282282
struct ImportThreadData {
283283
const ImportFile *reimport_files;
284284
int reimport_from;
285-
int max_index = 0;
285+
SafeNumeric<int> max_index;
286286
};
287287

288288
void _reimport_thread(uint32_t p_index, ImportThreadData *p_import_data);

0 commit comments

Comments
 (0)