Adding vertex attribute causes texture to not show

When I have this setup:

    float vertices[] =
     {
              0.5f,  0.5f,  0.5f,     1.0f, 1.0f,
              0.5f, -0.5f,  0.5f,     1.0f, 0.0f,
             -0.5f, -0.5f,  0.5f,     0.0f, 0.0f,
             -0.5f,  0.5f,  0.5f,     0.0f, 1.0f
    };
    unsigned int indices[] =
    {
            0,  1,  3,   // first triangle
            1,  2,  3,    // second triangle
    };


    unsigned int VAO, VBO, EBO;
    glGenVertexArrays(1, &VAO);
    glGenBuffers(1, &VBO);
    glGenBuffers(1, &EBO);

    glBindVertexArray(VAO);

    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
    glEnableVertexAttribArray(0);

    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
    glEnableVertexAttribArray(1);

    glBindVertexArray(0);

    ... (LOADING TEXTURE CODE)
 
    ... (LOADING SHADER CODE)

    glUseProgram(ProgramID);
    int loc = glGetUniformLocation(ProgramID, "texture1");
    glUniform1i(loc, 0);

    glEnable(GL_DEPTH_TEST);

    while (!window.IsClosed())
    {
        glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glUseProgram(ProgramID);
        glBindVertexArray(VAO);
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, textureID);
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

        glBindVertexArray(0);

    }

Vertex shader:

    #version 330 core

    layout (location = 0) in vec3 aPos;
    layout (location = 1) in vec2 aTexCoord;

    out vec2 TexCoord;

    void main()
    {
        TexCoord = aTexCoord;
        gl_Position = vec4(aPos, 1.0f);
    }

Fragment shader:

    #version 330 core

    in vec2 TexCoord;

    out vec4 FragColor;

    uniform sampler2D texture1;

    void main()
    {
        FragColor = texture(texture1, TexCoord);
    }

Everything works fine with this setup. The square has a texture.

However when I add normals like so:

        float vertices[] =
             {
                      0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 1.0f,  1.0f, 1.0f,   
                      0.5f, -0.5f,  0.5f,    0.0f, 0.0f, 1.0f,  1.0f, 0.0f,   
                     -0.5f, -0.5f,  0.5f,   0.0f, 0.0f, 1.0f,   0.0f, 0.0f,  
                     -0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 1.0f,  0.0f, 1.0f   
            };
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
        glEnableVertexAttribArray(2);

Even if I change nothing in the shaders, I end up with a black square. Why?
I omitted some code since it would make this too long, if you think that might be the reason, please ask and I will show it.

the shader code would be useful. The first thing that comes to mind is that the normals are inverted. If you have some basic lightning implemented then you would only see the black silhouette of the object.
EDIT: nevermind i found your shader.
I think you said here:

    glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
    glEnableVertexAttribArray(2);

to have the texturecoordinates at the 2. location. So you have to update your shader like this:

#version 330 core

layout (location = 0) in vec3 aPos;
layout (location = 2) in vec2 aTexCoord;//instead of location=1

out vec2 TexCoord;

Ah yes, that was the one thing I changed in the vertex shader. Yet the square is still black.
By the way, if I set the color of the square like so: FragColor = vec4(TexCoord, 0.0f, 1.0f), the colors of each corner of the square match up with what they should according to the texture coordinate leading me to believe that the data is being passed along fine. E.g. the upper right is yellow, lower left is black etc.

If the texture coordinates are fine, then the issue is with the texture.

My first guess would be that the texture doesn’t have all mipmap levels defined but the minification filter uses mipmaps. The initial value of GL_TEXTURE_MIN_FILTER is GL_NEAREST_MIPMAP_LINEAR, so you need to explicitly change it to GL_NEAREST or GL_LINEAR if the texture only has the base mipmap level.

Why do you want to delete this post? It might help someone who has a similar issue like you.