GLFW Icon debug assertion failed

I don’t know how this happen or how to fix it but what happened is that I tried using stb to load image for my window icon. However it always giving me an error about debug assertion failed for file_name != nullptr.

#if defined(_WIN32) || defined(_WIN64)
#define PLATFORM_NAME "Windows"
#include <Windows.h>
#elif defined(__APPLE__) || defined(__MACH__)
#define PLATFORM_NAME "Apple"
#elif defined(__ANDROID__)
#define PLATFORM_NAME "Android"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <iostream>
#include <glad.h>
// #include <glut.h>
// #include <freeglut.h>
#include <glfw3.h>
#include <stb_image.h>
#include <glm.hpp>
#include <gtc/matrix_transform.hpp>
#include <gtc/type_ptr.hpp>
#include "Position.h"
#include "WindowKeyInput.h"
#include "ErrorCallback.h"
#include <filesystem>
namespace fs = std::filesystem;

#include "ShaderClass.h"
#include "VAO.h"
#include "VBO.h"
#include "EBO.h"
#include "Texture.h"
#include "Camera.h"


const char helloWorld[] = "Hello World!\n";


GLfloat vertices[] =
{ //     COORDINATES     /        COLORS      /   TexCoord  //
    -0.5f, 0.0f,  0.5f,     0.83f, 0.70f, 0.44f,	0.0f, 0.0f,
    -0.5f, 0.0f, -0.5f,     0.83f, 0.70f, 0.44f,	5.0f, 0.0f,
     0.5f, 0.0f, -0.5f,     0.83f, 0.70f, 0.44f,	0.0f, 0.0f,
     0.5f, 0.0f,  0.5f,     0.83f, 0.70f, 0.44f,	5.0f, 0.0f,
     0.0f, 0.8f,  0.0f,     0.92f, 0.86f, 0.76f,	2.5f, 5.0f
};

GLuint indices[] =
{
    0, 1, 2,
    0, 2, 3,
    0, 1, 4,
    1, 2, 4,
    2, 3, 4,
    3, 0, 4
};

GLfloat lightVertices[] =
{//     COORDINATES     //
    -0.1f, -0.1f,  0.1f,
    -0.1f, -0.1f, -0.1f,
     0.1f, -0.1f, -0.1f,
     0.1f, -0.1f,  0.1f,
    -0.1f,  0.1f,  0.1f,
    -0.1f,  0.1f, -0.1f,
     0.1f,  0.1f, -0.1f,
     0.1f,  0.1f,  0.1f
};

GLuint lightIndices[] =
{
    0, 1, 2,
    0, 2, 3,
    0, 4, 7,
    0, 7, 3,
    3, 7, 6,
    3, 6, 2,
    2, 6, 5,
    2, 5, 1,
    1, 5, 4,
    1, 4, 0,
    4, 5, 6,
    4, 6, 7
};


int main()
{
    std::cout << helloWorld << std::endl;

    glfwSetErrorCallback(error_callback);

    glfwInit();
    
    if (!glfwInit())
    {
        throw std::runtime_error("Failed to initialize GLFW\n");
        return -1;
    }

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    // glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    

    int width = 640;
    int height = 480;

    GLFWwindow* window = glfwCreateWindow(width, height, "Game", NULL, NULL);
    glfwSetWindowPos(window, width / 2, height / 3);
    glfwGetWindowSize(window, &width, &height);

    if (!window)
    {
        glfwTerminate();
        return -1;
    }
    else if (window == NULL)
    {
        std::cout << "Failed to create GLFW window\n" << std::endl;
        glfwTerminate();
        return -1;
    }
    
    glfwMakeContextCurrent(window);

    GLFWimage icon[1];

    int imageWidth, imageHeight, channels;
    unsigned char* pixels = stbi_load("pop_cat.png", &imageWidth, &imageHeight, &channels, 4);

    icon[0].width = imageWidth;
    icon[0].height = imageHeight;
    icon[0].pixels = pixels;
    glfwSetWindowIcon(window, 1, icon);
    stbi_image_free(icon[0].pixels);

    glfwSetKeyCallback(window, window_key_input);

    gladLoadGL();
    
    glViewport(0, 0, width, height);
    
    Shader shaderProgram("default.vert", "default.frag");

    VAO VAO1;
    VAO1.Bind();

    VBO VBO1(vertices, sizeof(vertices));
    EBO EBO1(indices, sizeof(indices));

    VAO1.LinkAttrib(VBO1, 0, 3, GL_FLOAT, 8 * sizeof(float), (void*)0);
    VAO1.LinkAttrib(VBO1, 1, 3, GL_FLOAT, 8 * sizeof(float), (void*)(3 * sizeof(float)));
    VAO1.LinkAttrib(VBO1, 2, 2, GL_FLOAT, 8 * sizeof(float), (void*)(6 * sizeof(float)));
    VAO1.Unbind();
    VBO1.Unbind();
    EBO1.Unbind();

    Shader lightShader("light.vert", "light.frag");

    VAO lightVAO;
    lightVAO.Bind();

    VBO lightVBO(lightVertices, sizeof(lightVertices));
    EBO lightEBO(lightIndices, sizeof(lightIndices));

    lightVAO.LinkAttrib(lightVBO, 0, 3, GL_FLOAT, 3 * sizeof(float), (void*)0);

    lightVAO.Unbind();
    lightVBO.Unbind();
    lightEBO.Unbind();

    glm::vec4 lightColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
    glm::vec3 lightPos = glm::vec3(0.5f, 0.5f, 0.5f);
    glm::mat4 lightModel = glm::mat4(1.0f);
    lightModel = glm::translate(lightModel, lightPos);

    glm::vec3 meshPos = glm::vec3(0.0f, 0.0f, 0.0f);
    glm::mat4 meshModel = glm::mat4(1.0f);
    meshModel = glm::translate(meshModel, meshPos);

    lightShader.Activate();
    glUniformMatrix4fv(glGetUniformLocation(lightShader.ID, "model"), 1, GL_FALSE, glm::value_ptr(lightModel));
    shaderProgram.Activate();
    glUniformMatrix4fv(glGetUniformLocation(shaderProgram.ID, "model"), 1, GL_FALSE, glm::value_ptr(meshModel));

    GLuint uniID = glGetUniformLocation(shaderProgram.ID, "scale");

    Texture texture(0, GL_TEXTURE_2D, GL_TEXTURE0, GL_RGBA, GL_UNSIGNED_BYTE);
    texture.textureUnit(shaderProgram, "texture0", 0);

    glEnable(GL_DEPTH_TEST);

    Camera camera(width, height, glm::vec3(0.0f, 0.0f, 2.0f));

    while (!glfwWindowShouldClose(window))
    {
        glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        shaderProgram.Activate();
        camera.Inputs(window);
        camera.updateMatrix(45.0f, 0.1f, 100.0f);
        camera.Matrix(shaderProgram, "camMatrix");
        glUniform1f(uniID, 0.5f);
        texture.Bind();
        VAO1.Bind();
        glDrawElements(GL_TRIANGLES, sizeof(indices) / sizeof(int), GL_UNSIGNED_INT, 0);
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    VAO1.Delete();
    VBO1.Delete();
    EBO1.Delete();
    texture.Delete();
    shaderProgram.Delete();

    glfwDestroyWindow(window);
    glfwTerminate();
    return 0;
}

(this source code might be a bit similar because I use the tutorial from freecodecamp on youtube)

This is the error:

please help

Welcome to the GLFW forum.

Note that stbi_load isn’t a GLFW library function.

This assert would normally be triggered if you passed NULL instead of a filename, but it looks like you are passing "pop_cat.png" in the example code. To debug further you can click Retry and this should show you the code, callstack and local variables so you can debug the problem to figure out what’s wrong.