Skip to content

Commit 9f6c6b5

Browse files
danfiremanclaude
andcommitted
Fix LuaShader crash when debug.getinfo is unavailable in gadget context
LuaShader:GetHandle/Delete/Activate/ActivateWith guard their "invalid shader object" error path with `(debug and debug.getinfo(1).name)`. In gadget (LuaRules) Lua the engine strips debug.getinfo while leaving the debug table present, so the guard passes but debug.getinfo(1) is a nil call -> uncaught error. This turns a recoverable shader-compile failure into a fatal one: when a shader fails to compile (e.g. gfx_overdrive_cables' geometry shader on a driver lacking GL_ARB_gpu_shader5 in geometry shaders, such as older llvmpipe), the gadget handles it gracefully via RemoveGadget, but Shutdown -> cableShader:Finalize() then calls Delete() on a shader whose shaderObj is nil, hitting the guard. The resulting error propagates out of the pcall'd gadgets.lua include and aborts the ENTIRE LuaRules handle ("LuaRules is not loaded") instead of just disabling one effect. Fix: also check that debug.getinfo exists before calling it. Applied to all three vendored copies of LuaShader.lua. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 77e4094 commit 9f6c6b5

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

LuaRules/Gadgets/Include/LuaShader.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function LuaShader:GetHandle()
196196
if self.shaderObj ~= nil then
197197
return self.shaderObj
198198
else
199-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
199+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
200200
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()?", funcName))
201201
end
202202
end
@@ -205,7 +205,7 @@ function LuaShader:Delete()
205205
if self.shaderObj ~= nil then
206206
gl.DeleteShader(self.shaderObj)
207207
else
208-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
208+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
209209
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()", funcName))
210210
end
211211
end
@@ -217,7 +217,7 @@ function LuaShader:Activate()
217217
self.active = true
218218
return glUseShader(self.shaderObj)
219219
else
220-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
220+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
221221
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()", funcName))
222222
return false
223223
end
@@ -238,7 +238,7 @@ function LuaShader:ActivateWith(func, ...)
238238
glActiveShader(self.shaderObj, func, ...)
239239
self.active = false
240240
else
241-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
241+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
242242
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()", funcName))
243243
end
244244
end

LuaUI/Widgets/Include/LuaShader.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ function LuaShader:GetHandle()
758758
if self.shaderObj ~= nil then
759759
return self.shaderObj
760760
else
761-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
761+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
762762
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()?", funcName))
763763
end
764764
end
@@ -767,7 +767,7 @@ function LuaShader:Delete()
767767
if self.shaderObj ~= nil then
768768
gl.DeleteShader(self.shaderObj)
769769
else
770-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
770+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
771771
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()", funcName))
772772
end
773773
end
@@ -779,7 +779,7 @@ function LuaShader:Activate()
779779
self.active = true
780780
return glUseShader(self.shaderObj)
781781
else
782-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
782+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
783783
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()", funcName))
784784
return false
785785
end
@@ -800,7 +800,7 @@ function LuaShader:ActivateWith(func, ...)
800800
glActiveShader(self.shaderObj, func, ...)
801801
self.active = false
802802
else
803-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
803+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
804804
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()", funcName))
805805
end
806806
end

modules/graphics/LuaShader.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ function LuaShader:GetHandle()
929929
if self.shaderObj ~= nil then
930930
return self.shaderObj
931931
else
932-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
932+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
933933
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()?", funcName))
934934
end
935935
end
@@ -938,7 +938,7 @@ function LuaShader:Delete()
938938
if self.shaderObj ~= nil then
939939
gl.DeleteShader(self.shaderObj)
940940
else
941-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
941+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
942942
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()", funcName))
943943
end
944944
end
@@ -959,7 +959,7 @@ function LuaShader:Activate()
959959
end
960960
return glUseShader(self.shaderObj)
961961
else
962-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
962+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
963963
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()", funcName))
964964
return false
965965
end
@@ -980,7 +980,7 @@ function LuaShader:ActivateWith(func, ...)
980980
glActiveShader(self.shaderObj, func, ...)
981981
self.active = false
982982
else
983-
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
983+
local funcName = (debug and debug.getinfo and debug.getinfo(1).name) or "UnknownFunction"
984984
self:ShowError(string.format("Attempt to use invalid shader object in [%s](). Did you call :Compile() or :Initialize()", funcName))
985985
end
986986
end

0 commit comments

Comments
 (0)