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

public bool TryFindByCode(ulong code, out DwarfAbbreviationItem item) failed #28

Open
Albert-Coder opened this issue Jul 25, 2023 · 0 comments
Labels
bug Something isn't working Help Welcome A pull-request is welcome to fix this issue

Comments

@Albert-Coder
Copy link

Albert-Coder commented Jul 25, 2023

in DwarfAbbreviation.cs line 87;

   `public bool TryFindByCode(ulong code, out DwarfAbbreviationItem item)
    {
        item = null;
        if (code == 0)
        {
            return `false;
        }

        code--;

        if (_mapItems.Count > 0)
        {
            return _mapItems.TryGetValue(code, out item);
        }

        if (code < int.MaxValue && (int)code < _items.Count)
        {
            item = _items[(int) code];
            return true;
        }

        item = null;
        return false;
    }`

I found sometimes it failed at return _mapItems.TryGetValue(code, out item);
Then I fixed below; I do not konw if you have the same problem;

    `public` bool TryFindByCode(ulong code, out DwarfAbbreviationItem item)
    {
        item = null;
        if (code == 0)
        {
            return false;
        }

        //no need to minus 1
        //code--;

        if (_mapItems.Count > 0)
        {
            return _mapItems.TryGetValue(code, out item);
        }

        //if _mapItems is empty, try _items;
        if (code < int.MaxValue && (int)code <= _items.Count)
        {
            item = _items[(int) code - 1];
            return true;
        }

        item = null;
        return false;
    }
@xoofx xoofx added bug Something isn't working Help Welcome A pull-request is welcome to fix this issue labels Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Help Welcome A pull-request is welcome to fix this issue
Projects
None yet
Development

No branches or pull requests

2 participants