CharmedBaryon / CommonLibSSE-NG

This is a reverse engineered library for Skyrim Special Edition and Skyrim VR.
MIT License
142 stars 32 forks source link

Unable to obtain keyword #68

Open cppcooper opened 1 year ago

cppcooper commented 1 year ago

This code seems to exhibit UB, sometimes getting the keyword would work.. but most of the time it is null. And sometimes it crashes.

if (auto actor = a_ref->As<RE::Actor>(); actor) {
    auto dobj = RE::BGSDefaultObjectManager::GetSingleton();
    if (!dobj) {
        logger::error("This was it, the segfault. dobj was null"); //said line 112, which was an empty line after animal_keyword =
        return false;
    }
    auto animal_keyword = dobj->GetObject<RE::BGSKeyword>(RE::DEFAULT_OBJECT::kKeywordAnimal);

    // actor was already checked
    if (!actor->IsDead()
        || actor->IsSummoned()
        || (disable_for_animals && actor->HasKeyword(animal_keyword)))
    {
        return false;
    }
}

Could be related to #66