Reported by @Porteries Tristan (panzergame) in D1414.
glDisable calls with bad enum argument GL_TEXTURE_2D_MULTISAMPLE that came from this line:
tex->target = (n == 1) ? GL_TEXTURE_1D : (samples ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D);
Probably, similar changes should be done for glEnable. I'm not sure how to fix this correctly.
Reproduced this by pressing "OpenGL render active viewport" button.