fix cpp crash

Signed-off-by: 刘玉龙 <liuyulong44@h-partners.com>
This commit is contained in:
刘玉龙 2024-11-02 15:49:03 +08:00
parent 2622758e16
commit ee20592044
4 changed files with 25 additions and 19 deletions

View File

@ -131,7 +131,7 @@ public:
}
std::pair<std::string, RefPtr<NG::UINode>> OnGetChildByIndex(
int32_t index, std::unordered_map<std::string, NG::LazyForEachCacheChild>& cachedItems) override
int32_t index, std::unordered_map<std::string, NG::LazyForEachCacheChild>& expiringItems) override
{
std::pair<std::string, RefPtr<NG::UINode>> info;
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(executionContext_, info);
@ -143,11 +143,10 @@ public:
params[paramType::Data] = CallJSFunction(getDataFunc_, dataSourceObj_, index);
params[paramType::Index] = JSRef<JSVal>::Make(ToJSValue(index));
std::string key = keyGenFunc_(params[paramType::Data], index);
auto cachedIter = cachedItems.find(key);
if (cachedIter != cachedItems.end()) {
info.first = key;
info.second = cachedIter->second.second;
cachedItems.erase(cachedIter);
GetChildFromExpiringItems(key, expiringItems, info);
// if info.second is null, the following ui node creation process is needed to fill info.second
if (info.second != nullptr) {
return info;
}
@ -162,7 +161,7 @@ public:
auto jsElmtIds = itemGenFunc_->Call(JSRef<JSObject>(), paramType::MAX_PARAMS_SIZE, params);
std::string lastKey = UpdateDependElmtIds(info.second, jsElmtIds, key);
changedLazyForEachNodes_.erase(nodeIter);
cachedItems.erase(lastKey);
expiringItems.erase(lastKey);
return info;
}
@ -206,15 +205,11 @@ public:
} else {
key = keyGenFunc_(params[paramType::Data], index);
}
auto expiringIter = expiringItems.find(key);
if (expiringIter != expiringItems.end()) {
info.first = key;
info.second = expiringIter->second.second;
expiringItems.erase(expiringIter);
// if info.second is null, the following ui node creation process is needed to fill info.second
if (info.second != nullptr) {
return info;
}
GetChildFromExpiringItems(key, expiringItems, info);
// if info.second is null, the following ui node creation process is needed to fill info.second
if (info.second != nullptr) {
return info;
}
NG::ScopedViewStackProcessor scopedViewStackProcessor;
@ -255,6 +250,17 @@ private:
std::map<int32_t, RefPtr<NG::UINode>> changedLazyForEachNodes_;
std::map<RefPtr<NG::UINode>, std::pair<std::set<uint32_t>, std::string>> dependElementIds_;
enum paramType {Data = 0, Index, Initialize, ElmtIds, MIN_PARAMS_SIZE = ElmtIds, MAX_PARAMS_SIZE};
void GetChildFromExpiringItems(std::string key,
std::unordered_map<std::string, NG::LazyForEachCacheChild>& expiringItems,
std::pair<std::string, RefPtr<NG::UINode>>& info)
{
auto expiringIter = expiringItems.find(key);
if (expiringIter != expiringItems.end()) {
info.first = key;
info.second = expiringIter->second.second;
expiringIter->second.second = nullptr;
}
}
};
} // namespace OHOS::Ace::Framework

View File

@ -47,7 +47,7 @@ namespace OHOS::Ace::NG {
}
CHECK_NULL_RETURN(itemInfo.second, itemInfo);
if (isCache) {
expiringItem_.emplace(itemInfo.first, LazyForEachCacheChild(index, itemInfo.second));
expiringItem_[itemInfo.first] = LazyForEachCacheChild(index, itemInfo.second);
cachedItems_[index] = LazyForEachChild(itemInfo.first, nullptr);
} else {
cachedItems_[index] = itemInfo;

View File

@ -297,7 +297,7 @@ protected:
}
virtual LazyForEachChild OnGetChildByIndex(
int32_t index, std::unordered_map<std::string, LazyForEachCacheChild>& cachedItems) = 0;
int32_t index, std::unordered_map<std::string, LazyForEachCacheChild>& expiringItems) = 0;
virtual LazyForEachChild OnGetChildByIndexNew(int32_t index,
std::map<int32_t, LazyForEachChild>& cachedItems,

View File

@ -138,7 +138,7 @@ int32_t OH_ArkUI_NodeAdapter_GetAllItems(ArkUI_NodeAdapterHandle handle, ArkUI_N
}
*items = new ArkUI_NodeHandle[*size] {};
for (uint32_t i = 0; i < *size; i++) {
(*items[i]) = reinterpret_cast<ArkUI_NodeHandle>(fullImpl->getExtendedAPI()->getAttachNodePtr(innerNodes[i]));
(*items)[i] = reinterpret_cast<ArkUI_NodeHandle>(fullImpl->getExtendedAPI()->getAttachNodePtr(innerNodes[i]));
}
delete[] innerNodes;
return OHOS::Ace::ERROR_CODE_NO_ERROR;