When compiled using /O2 /GL optimization, my OpenGL program encounters GL_ERROR 1282 during execution, making any use of OpenGL functionality impossible. If the whole program optimization (/GL) ist disabled, no GL errors occur and the program runs just fine.
Furthermore the error only occurs when a certain method, that in turn calls several methods that make heavy use of OpenGL functions, is called repeatingly and can also be fixed by inserting a random std::cout output into the method.
To reproduce the problem you can check the source code and Visual Studio solution online, although on different (graphics) hardware the behaviour of the application might change due to drivers etc. (I observed this on my laptop)
The code is openly accessable at