Fix crash in LoadMerch by clearing/placing refs in main thread
This commit is contained in:
@@ -109,19 +109,21 @@ bool LoadMerchandiseImpl(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since this method is running asyncronously in a thread, set up a callback on the trigger ref that will receive an event with the result
|
|
||||||
SKSE::RegistrationMap<bool> regMap = SKSE::RegistrationMap<bool>();
|
|
||||||
regMap.Register(toggle_ref, RE::BSFixedString("OnLoadMerchandise"));
|
|
||||||
|
|
||||||
RE::TESObjectREFR * merchant_chest = merchant_shelf->GetLinkedRef(chest_keyword);
|
RE::TESObjectREFR * merchant_chest = merchant_shelf->GetLinkedRef(chest_keyword);
|
||||||
if (!merchant_chest) {
|
if (!merchant_chest) {
|
||||||
logger::error("LoadMerchandise merchant_chest is null!");
|
logger::error("LoadMerchandise merchant_chest is null!");
|
||||||
regMap.SendEvent(false);
|
|
||||||
regMap.Unregister(toggle_ref);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FFIResult<MerchRecordVec> result = get_merchandise_list(api_url.c_str(), api_key.c_str(), merchandise_list_id);
|
FFIResult<MerchRecordVec> result = get_merchandise_list(api_url.c_str(), api_key.c_str(), merchandise_list_id);
|
||||||
|
|
||||||
|
// Placing the refs must be done on the main thread otherwise disabling & deleting refs in ClearMerchandiseImpl causes a crash
|
||||||
|
auto task = SKSE::GetTaskInterface();
|
||||||
|
task->AddTask([result, merchant_chest, merchant_shelf, placeholder_static, shelf_keyword, item_keyword, prev_keyword, next_keyword, page, toggle_ref, cell, data_handler, a_vm, extra_linked_ref_vtbl, MoveTo_Native, PlaceAtMe_Native]() {
|
||||||
|
// Since this method is running asyncronously in a thread, set up a callback on the trigger ref that will receive an event with the result
|
||||||
|
SKSE::RegistrationMap<bool> regMap = SKSE::RegistrationMap<bool>();
|
||||||
|
regMap.Register(toggle_ref, RE::BSFixedString("OnLoadMerchandise"));
|
||||||
|
|
||||||
if (result.IsOk()) {
|
if (result.IsOk()) {
|
||||||
logger::info("LoadMerchandise get_merchandise_list result OK");
|
logger::info("LoadMerchandise get_merchandise_list result OK");
|
||||||
MerchRecordVec vec = result.AsOk();
|
MerchRecordVec vec = result.AsOk();
|
||||||
@@ -135,6 +137,7 @@ bool LoadMerchandiseImpl(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ClearMerchandiseImpl(merchant_chest, merchant_shelf, placeholder_static, shelf_keyword, item_keyword);
|
ClearMerchandiseImpl(merchant_chest, merchant_shelf, placeholder_static, shelf_keyword, item_keyword);
|
||||||
|
|
||||||
logger::info(FMT_STRING("LoadMerchandise current shelf page is: {:d}"), merchant_shelf->extraList.GetCount());
|
logger::info(FMT_STRING("LoadMerchandise current shelf page is: {:d}"), merchant_shelf->extraList.GetCount());
|
||||||
@@ -356,13 +359,13 @@ bool LoadMerchandiseImpl(
|
|||||||
next_ref->SetDisplayName("(No next page)", true);
|
next_ref->SetDisplayName("(No next page)", true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
next_ref->SetDisplayName(fmt::format("Advance to page %d", page + 1).c_str(), true);
|
next_ref->SetDisplayName(fmt::format("Advance to page {:d}", page + 1).c_str(), true);
|
||||||
}
|
}
|
||||||
if (page == 1) {
|
if (page == 1) {
|
||||||
prev_ref->SetDisplayName("(No previous page)", true);
|
prev_ref->SetDisplayName("(No previous page)", true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
prev_ref->SetDisplayName(fmt::format("Back to page %d", page - 1).c_str(), true);
|
prev_ref->SetDisplayName(fmt::format("Back to page {:d}", page - 1).c_str(), true);
|
||||||
}
|
}
|
||||||
// auto messaging = SKSE::GetModCallbackEventSource();
|
// auto messaging = SKSE::GetModCallbackEventSource();
|
||||||
// const SKSE::ModCallbackEvent event = { RE::BSFixedString("BazaarRealm_LoadMerchandiseDone"), RE::BSFixedString(""), 0, nullptr };
|
// const SKSE::ModCallbackEvent event = { RE::BSFixedString("BazaarRealm_LoadMerchandiseDone"), RE::BSFixedString(""), 0, nullptr };
|
||||||
@@ -376,9 +379,9 @@ bool LoadMerchandiseImpl(
|
|||||||
regMap.Unregister(toggle_ref);
|
regMap.Unregister(toggle_ref);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
regMap.SendEvent(true);
|
regMap.SendEvent(true);
|
||||||
regMap.Unregister(toggle_ref);
|
regMap.Unregister(toggle_ref);
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user