azerothcore/mod-eluna

Item:GetItemLink case server crash

Closed this issue · 2 comments

icaca commented

RegisterPlayerEvent(PLAYER_EVENT_ON_STORE_NEW_ITEM) is fired when the player creates a character. Try to use Item:GetItemLink, the server will restart without any log.

function OnLoot(event, player, item, count)
    print(item:GetItemLink(4))
end

RegisterPlayerEvent(53, OnLoot)

Always Null-check variables that might not have a value before accessing them.
Example:

function OnLoot(event, player, item, count)
    if item
        print(item:GetItemLink(4))
    else
        print("item was null")
    end
end

RegisterPlayerEvent(53, OnLoot)

Object variables are prone to that behaviour and it is on the programmer to catch it.

icaca commented

This is just an example, the actual running code has judged nil.
even if it is nil, it should report an error.