The documentation for glDeleteProgram says that if the program to be deleted is currently bound then it won't actually be deleted until another program is selected. The mesa meta code tries to save and restore most of the GL state before using GL calls to do some operations including saving the GL program. However it just stores the GL program number and then calls glUseProgram(0) to disable it. If glDeleteProgram was already called on this program then this will end up freeing the program. When the meta code later tries to restore the state glUseProgram will throw a GL error because the saved program number is no longer valid. Attached is an example program demonstrating the bug. It creates a fragment shader which just sets the fragment color to green. It makes the program current and then immediately deletes it. It then draws two quads while the program is active but it calls glDrawPixels in between. glDrawPixels ends up using the meta save/restore code which causes the program to be deleted so the second quad ends up red.
Created attachment 39843 [details] Example showing the bug
Thanks for the testcase! I converted it into a piglit test: commit 782738e3cc4a6bb032a94f3cf7a2286f73d6a210 Author: Eric Anholt <eric@anholt.net> Date: Fri Oct 29 11:06:27 2010 -0700 useprogram-refcount-1: New test for a bug in Mesa metaops. and fixed the bug: commit a974949f3b586eee2bc8d6d97d3adb71796fe167 Author: Eric Anholt <eric@anholt.net> Date: Fri Oct 29 11:28:38 2010 -0700 mesa: Make metaops use program refcounts instead of names. Fixes failure on restoring state when the program was active but deleted, and the name no longer exists. Bug #31194
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.