I have come across an unusual bug in my program. I have a simple 3D renderer program I have been working on that loads an OBJ file and renders it, with some controls such as zoom, pan and rotate the camera. However, occasionally when the program is run (either through VS Code or simply by clicking the EXE file) the view comes up blank. The outputs are the same even when nothing is rendered and when trying to run it through RenderDoc it always seems to work. In the attached picture, the blank view happened after 3 working attempts (I just closed 2 of them). A shortened version of my rendering code looks like this:
unsigned int VAO;
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
unsigned int VBO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*18*(numinds), newVertArr, GL_STATIC_DRAW);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float),(void*)0);
glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,3*sizeof(float),(void*)(9*sizeof(float)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glUseProgram(shaderProgram);
glBindVertexArray(VAO);
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
while(!glfwWindowShouldClose(window)){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
formYRotMat(camRotHorMat, cameraRotation[0]);
formXRotMat(camRotVertMat, cameraRotation[1]);
glUniformMatrix4fv(projMatUniform, 1, GL_TRUE, projMat);
glUniformMatrix4fv(camRotHor, 1, GL_TRUE, camRotHorMat);
glUniformMatrix4fv(camRotVert, 1, GL_TRUE, camRotVertMat);
glUniform3f(originShader,origin[0],origin[1],origin[2]);
glUniform3f(camDirShader, camVector[0],camVector[1], camVector[2]);
glUniform1f(distanceShader,distance);
glDrawArrays(GL_TRIANGLES, 0, 18*numinds);
glfwSwapBuffers(window);
glfwPollEvents();
}