beyond-all-reason / beyond-all-reason/RecoilEngine
Weird lua issue with chobby
- Dominant language
- C++
- Stars
- 683
- Forks
- 293
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 40
Description
### Preface
I'm not sure what's going on here, but maybe together we can find out. Might be something stupid I'm overlooking, but I'll post here my findings.
Please excuse me if I'm misinterpreting something here very badly, but atm I'm baffled by the weird lua behaviour here.
### The situation
There was a report from a player with the following error:
`Error: in Chili lobby:layoutpanel185 : [string "libs/chiliui/chili/headers/util.lua"]:168: attempt to perform arithmetic on upvalue 'stackN' (a function value)`
This doesn't seem smth that always happens, but just in some particular situations. In that specific report the user was complaining [at discord](https://discord.com/channels/549281623154229250/1313918292167098368) (support-bugs > blackscreen in lobby) about a very bad blackscreen problem, he tried disconnecting some his extra monitors and that seemed to help.
The weird thing is, stackN there seems to be an integer in all situations:
```LUA
./libs/chiliui/chili/headers/util.lua:local stackN = 1
./libs/chiliui/chili/headers/util.lua: stackN = stackN + 1
./libs/chiliui/chili/headers/util.lua: stackN = stackN - 1
./libs/chiliui/chili/headers/util.lua: assert(stackN >= 1)
./libs/chiliui/chili/headers/util.lua: if (stackN == 1) then
```
(that's all appearances of stackN in the chobby codebase)
### Investigation
Can't say what's going on there, could be a bad error backtrace? investigating a bit, I found this document:
https://github.com/dlaurie/lua-notes/blob/master/upvalues.txt
This part of the text looks like it might be relevant, but it also could not be (and could actually be obsolete, or just not applicable here):
```
I.e., there is an upvalue `_ENV`, but it is not the first. Loading
`_ENV` into the first upvalue is worse than useless.
A good idiom for functions that will be saved and loaded as binary
chunks is therefore to put
local _ENV = _ENV
```
### Full traces:
[spring-launcher-20241213T171109.log](https://github.com/user-attachments/files/18135320/spring-launcher-20241213T171109.log)
some snippets with errors:
```
# this one is likely something else, but putting it here since it's also in the log
[2024-12-13 18:11:29.395] [info] [t=00:00:16.558954][f=-000001] Download Handler Listener Error, [string "libs/chiliui/chili/controls/control.lua"]:1200: ActiveFBO(): OpenGL calls can only be used in Draw() call-ins, or while creating display lists, DownloadFinished
```
```
[2024-12-13 18:13:05.802] [warn] [t=00:01:52.964739][f=-000001] [Chili] Error: in `Chili lobby`:layoutpanel185 : [string "libs/chiliui/chili/headers/util.lua"]:168: attempt to perform arithmetic on upvalue 'stackN' (a function value)
[2024-12-13 18:13:05.802] [warn] [t=00:01:52.964887][f=-000001] [Chili] Error: stacktrace:
[string "libs/chiliui/chili/headers/util.lua"]:168: in PopScissor
[string "libs/chiliui/chili/headers/util.lua"]:258: in PopLimitRenderRegion
[string "libs/chiliui/chili/controls/control.lua"]:1228: in _DrawInClientArea
[string "libs/chiliui/chili/controls/control.lua"]:1273: in _DrawChildrenInClientArea
... (41 calls)
[string "LuaHandler/handler.lua"]:981
[string "libs/chiliui/chili/controls/object.lua"]:779: in fnc
[t=00:01:52.964899][f=-000001] [Chili] Error: In widget: Chili lobby
[t=00:01:52.964921][f=-000001] Error: DrawScreen: OpenGL stack check error, matrix mode = GL_MODELVIEW, depth = 14, please make sure to pop all matrices before end
```
Contributor guide
Research direction
Start with libs/chiliui/chili/headers/util.lua around line 168 and trace the PopScissor and PopLimitRenderRegion callers shown in the log. Compare the full spring-launcher-20241213T171109.log with the reported OpenGL stack error and investigate whether the failure can be reproduced in the Chili lobby. Done means the cause of stackN becoming a function is identified and the behavior is fixed or clearly documented as an external runtime issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100