[Python] what is this unnamed error and how to fix it?

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I am working on a costume 3D game engine which uses Python and the ModernGL library. Every time I run the code, I get this error for my shader program:

    Traceback (most recent call last):
    File "h:\Projects\Python\HyperDoom project\main.py", line 20, in <module>
    game: Game = Game("ROMS\\DOOM.WAD")
    ~~~~^^^^^^^^^^^^^^^^^^
    File "h:\Projects\Python\HyperDoom project\main.py", line 11, in __init__
    self.Engine: Engine = Engine((1280, 720), self.E1M1, self.wadData)
    ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "h:\Projects\Python\HyperDoom project\engin3d.py", line 29, in __init__
    self.lData: LevelData = LevelData(data, self)
    ~~~~~~~~~^^^^^^^^^^^^
    File "h:\Projects\Python\HyperDoom project\level_data.py", line 26, in __init__
    self.mesh: Mesh = Mesh(self.ctx, self)
    ~~~~^^^^^^^^^^^^^^^^
    File "h:\Projects\Python\HyperDoom project\Mesh.py", line 8, in __init__
    self.vaos: VAOs = VAOs(ctx, level)
    ~~~~^^^^^^^^^^^^
    File "h:\Projects\Python\HyperDoom project\VAOs.py", line 13, in __init__
    self.vaos["level/test"] = self.getVao(
    ~~~~~~~~~~~^
    self.programs.programs['test'],
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    self.vbos.vbos['level']
    ^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
    File "h:\Projects\Python\HyperDoom project\VAOs.py", line 23, in getVao
    vao = self.ctx.vertex_array(program, [(vbo, '3f 3f 2f 1i', "in_position", "in_color", "in_uv", "in_layer")])
    File "C:\Users\Yusof\AppData\Local\Programs\Python\Python313\Lib\site-packages\moderngl\__init__.py", line 1901, in vertex_array
    return self._vertex_array(*args, **kwargs)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
    File "C:\Users\Yusof\AppData\Local\Programs\Python\Python313\Lib\site-packages\moderngl\__init__.py", line 1918, in _vertex_array
    attribs = [types[x] if type(x) is int else types[locations[x]] for x in attribs]
    ~~~~~~~~~^^^
    KeyError: 'in_layer'


    I don't know what this error means. It even doesn't have a name or explanation. It just writes the variable's name.

    This is my vertex shader:

    #version 330 core

    layout (location = 0) in vec3 in_position;
    layout (location = 1) in vec3 in_color;
    layout (location = 2) in vec2 in_uv;
    layout (location = 3) in int in_layer;

    out vec4 frag_color;
    out vec2 frag_uv;
    flat out int frag_layer;

    uniform mat4 m_proj;
    uniform mat4 m_view;
    uniform mat4 m_model;

    void main() {
    frag_color = vec4(in_color, 1.0);
    frag_uv = in_uv;
    frag_layer = in_layer;
    gl_Position = m_proj * m_view * m_model * vec4(in_position, 1);
    }


    and this my fragment shader:

    #version 330 core

    in vec4 frag_color;
    in vec2 frag_uv;

    flat in int frag_layer;

    out vec4 color;

    uniform sampler2DArray flats;

    void main() {
    color = texture(flats, vec3(frag_uv, 0)) + (frag_color) * 2 - frag_color - frag_color + frag_layer * 2;
    }


    In case the problem is from vao, this the definition:

    vao = self.ctx.vertex_array(program, [(vbo, '3f 3f 2f 1i', "in_position", "in_color", "in_uv", "in_layer")])


    What is this error and how can I fix it?

    At first, I thought this error was because that I didn't use that variable, which is why I wrote such ca omplex expression for frag_color. But it seems that this is not the case.

    Continue reading...

Compartilhe esta Página