azerothcore / mod-eluna

Eluna Lua Engine © for WoW Emulators
https://elunaluaengine.github.io/
GNU General Public License v3.0
100 stars 130 forks source link

ResetPetTalents case server crash #107

Closed kissingers closed 1 year ago

kissingers commented 1 year ago

now the function will case the server crash

    int ResetPetTalents(lua_State* /*L*/, Player* player)
    {
#ifndef TRINITY
        Pet* pet = player->GetPet();
        Pet::resetTalentsForAllPetsOf(player, pet);
        if (pet)
            player->SendTalentsInfoData(true);
#else
        player->ResetPetTalents();
        player->SendTalentsInfoData(true);
#endif
        return 0;
    }

if change to below code, the crash will not action, and work ok

    int ResetPetTalents(lua_State* /*L*/, Player* player)
    {
#ifndef TRINITY
        player->ResetPetTalents();
#else
        player->ResetPetTalents();
        player->SendTalentsInfoData(true);
#endif
        return 0;
    }

as below function include the SendTalentsInfoData(true); so the player->SendTalentsInfoData(true); not need

void Player::ResetPetTalents()
{
    // This needs another gossip option + NPC text as a confirmation.
    // The confirmation gossip listid has the text: "Yes, please do."
    Pet* pet = GetPet();

    if (!pet || pet->getPetType() != HUNTER_PET || pet->m_usedTalentCount == 0)
        return;

    CharmInfo* charmInfo = pet->GetCharmInfo();
    if (!charmInfo)
    {
        LOG_ERROR("entities.player", "Object ({}) is considered pet-like but doesn't have a charminfo!", pet->GetGUID().ToString());
        return;
    }
    pet->resetTalents();
    SendTalentsInfoData(true);
}

So I think only call player->ResetPetTalents(); and do nothing will fix the crash, or #ifndef azerothcore use player->ResetPetTalents(); only?

    int ResetPetTalents(lua_State* /*L*/, Player* player)
    {
        player->ResetPetTalents();
        return 0;
    }