1

Create cell storage in a task, fixes CTD when accessing a created container from another thread

This commit is contained in:
Eddoursul 2022-07-12 20:27:35 +02:00
parent 4a1218782f
commit 7918a84386
3 changed files with 12 additions and 13 deletions

Binary file not shown.

Binary file not shown.

View File

@ -375,21 +375,20 @@ namespace ArtifactTracker
log::info("Adding new storage in {}", cell->GetName()); log::info("Adding new storage in {}", cell->GetName());
#endif #endif
cellStorage = RE::PlayerCharacter::GetSingleton()->PlaceObjectAtMe(g_cellContainer, true).get(); SKSE::GetTaskInterface()->AddTask([&]() {
cellStorage = RE::PlayerCharacter::GetSingleton()->PlaceObjectAtMe(g_cellContainer, true).get();
if (cellStorage) { if (cellStorage) {
cellStorage->Disable(); cellStorage->Disable();
g_persistentStorage->AddForm(cellStorage); g_persistentStorage->AddForm(cellStorage);
g_persistentMap[cellStorage->formID] = cellStorage; g_persistentMap[cellStorage->formID] = cellStorage;
ToggleHomeMode(cellStorage); ToggleHomeMode(cellStorage);
std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
SyncCellStorage(); SyncCellStorage();
}).detach(); } else {
} else { log::error("Failed to create cell storage in OnCellEnter");
log::error("Failed to create cell storage in OnCellEnter"); ToggleHomeMode(nullptr);
ToggleHomeMode(nullptr); }
} });
} }
void SyncCellStorage(const RE::TESObjectREFR* a_ignoreRef) void SyncCellStorage(const RE::TESObjectREFR* a_ignoreRef)