Mesa freezes when the GLSL shader contains a `for` loop with an uninitialized `i` index/counter variable
Submitted by Swyter
Assigned to mes..@..op.org
Link to original bug (#105755)
Description
Created attachment 138364 default.frag
So yeah, this has baffled me for a while. I have had reports of soft-locks and freezes of my OpenGL/SDL2 game in Mesa-based Linux distros for a while, mainly under Intel hardware. The game works fine in Windows and macOS using the same shaders. Luckily I have just found out that it also happens under Nouveau, so the problem seems to be at the GLSL parser-level or other shared/common component.
After debugging the soft-locking issue for a bit it was clear that it only happened whenever the dynamic point lights code path was in use. After disabling and enabling it I suddenly realized something:
for (int i; i < lightCount; i++)
I forgot to initialize the counter of the loop and that completely froze the entire graphics pipeline, making the system unusable!
I find it funny that glslangValidator doesn't throw any error or warning even if that should cause undefined behavior. Looks like the proprietary AMD and NVIDIA OpenGL drivers initialize the i
indexing variable to zero, which looks like the sane thing to do.
It was my mistake, I'll try to lint them better. But the consequences are a bit unforgiving.
PS: I'd attach an apitrace, but everything freezes. Let me know if you need anything else, maybe we can give a bunch Steam keys to Mesa developers, in case they are needed. The game is called Sphinx and the Cursed Mummy, a native OpenGL 3+ port.
Attachment 138364, "default.frag":
default.frag