Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: AOR for Item Rarities on Item Description Window #2398

Open
1 task done
WeylonSantana opened this issue Nov 25, 2024 · 2 comments
Open
1 task done

bug: AOR for Item Rarities on Item Description Window #2398

WeylonSantana opened this issue Nov 25, 2024 · 2 comments
Labels
bug Something isn't working verified Issue has been verified as valid/existing.

Comments

@WeylonSantana
Copy link
Contributor

WeylonSantana commented Nov 25, 2024

Description

It's very easy to cause an error here and get an ArgumentOutOfRange Exception, we should have a check to see if it's within the Range to avoid crashes (and maybe in other possible places where rarity is used too?)

var rarityName = Options.Instance.Items.RarityTiers[mItem.Rarity];

Steps to Reproduce

  1. create a item with the highest rarity and save
  2. remove the highest rarity on server and restart
  3. show item description window (over mouse on item) on client will crash the client

Version with bug

current

Last version that worked well

Unknown

Affected platforms

Windows

Did you find any workaround?

we must check if it is within the range before trying to obtain the value if is not on range, then set the lowest rarity

Relevant log output

No response

Duplicate Bug Check

  • This bug report is not a duplicate to the best of my knowledge.
@WeylonSantana WeylonSantana added bug Something isn't working needs verification Pending confirmation that the bug exists by another user. verified Issue has been verified as valid/existing. and removed needs verification Pending confirmation that the bug exists by another user. labels Nov 25, 2024
@dhmello
Copy link
Contributor

dhmello commented Nov 25, 2024

Can u test?

try
{
    // Ensure mItem.Rarity is within the valid range of RarityTiers.
    if (mItem.Rarity >= 0 && mItem.Rarity < Options.Instance.Items.RarityTiers.Count)
    {
        var rarityName = Options.Instance.Items.RarityTiers[mItem.Rarity];
        _ = Strings.ItemDescription.Rarity.TryGetValue(rarityName, out var rarityLabel);
        header.SetDescription(rarityLabel, rarityColor ?? Color.White);
    }
    else
    {
        // Log a warning if the rarity is invalid and set default values.
        Log.Warn($"Invalid rarity index: {mItem.Rarity}. Defaulting to White rarity.");
        header.SetDescription("Common", Color.White);
    }
}
catch (Exception exception)
{
    Log.Error(exception);
    throw;
}

header.SizeToChildren(true, false);

@WeylonSantana
Copy link
Contributor Author

I don't think all this is necessary to avoid the crash, the best would be to just use a Math.min

var rarityName = Options.Instance.Items.RarityTiers[Math.Min(mItem.Rarity, Options.....RarityTiers.Count)];

If the lowest is Rarity, ok, within the range, if not, it will be the highest possible. This way, the dev would have a visual indicator ingame to understand that something is not right with the rarities without crashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working verified Issue has been verified as valid/existing.
Projects
None yet
Development

No branches or pull requests

2 participants