C#C
C#14mo ago
Tofaa

Dictionary<> Keys do not get fetched properly

    private readonly Dictionary<NamespacedKey, Texture2D> _textures = new();

    internal void Load() {
        var path = "assets/textures";
        var files = Directory.GetFiles(path);
        foreach (var file in files) {
            var texture = Raylib.LoadTexture(file);
            var id = NamespacedKey.texture(file.Replace("assets/textures\\", "").Replace(".png", ""));
            _textures.Add(id, texture);
            Console.WriteLine("Loaded texture with id " + id.Full + " Texture Format:" + texture.Format);
        }
    }

    internal void Unload() {
        foreach (var texture in _textures) {
            Raylib.UnloadTexture(texture.Value);
        }
    }


NamespacedKey is just a class that stores 3 strings.
I override the GetHashCode() method in it to
    public override int GetHashCode()
    {
        return Domain.GetHashCode() + Key.GetHashCode() + Family.GetHashCode();
    }

Ive tried different hashcodes incase im just stupid but nothing works
Was this page helpful?