Crash when doing a lot of fetching in ZScript
Moderator: GZDoom Developers
Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Crash when doing a lot of fetching in ZScript
Versions: GZDoom 3.1.0 and GZDoom g3.2pre-119-gac811f9
Both are x64.
What I have attached below is a HUD, but it has no graphics. Everything has been stripped to pinpoint the issue. Keep in mind that due to the nature of the error I had to make a lot of CVARs! (135 to be precise. No more, no less.) I suggest to backup your ini or burn it afterwards.
So, onto the point. What happens is that whenever I'd run the game, it'd crash. However, if you open up ZScript.txt and comment out any line in void UpdateKills(), there will be no crash on start-up. What I did may be a clear case of "Don't do that!", in which case I'd love to hear a suggestion on how to update variables. It's only a mere guess that adding some sort of a delay between calls to UpdateKills() and doing checks periodically would be a better idea, but I haven't tried that yet.
EDIT: Attached CrashReport, for what it's worth.
Both are x64.
What I have attached below is a HUD, but it has no graphics. Everything has been stripped to pinpoint the issue. Keep in mind that due to the nature of the error I had to make a lot of CVARs! (135 to be precise. No more, no less.) I suggest to backup your ini or burn it afterwards.
So, onto the point. What happens is that whenever I'd run the game, it'd crash. However, if you open up ZScript.txt and comment out any line in void UpdateKills(), there will be no crash on start-up. What I did may be a clear case of "Don't do that!", in which case I'd love to hear a suggestion on how to update variables. It's only a mere guess that adding some sort of a delay between calls to UpdateKills() and doing checks periodically would be a better idea, but I haven't tried that yet.
EDIT: Attached CrashReport, for what it's worth.
- Attachments
-
- CrashReport.zip
- (19.2 KiB) Downloaded 20 times
-
- CrashWad.wad
- (14.38 KiB) Downloaded 22 times
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49067
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Crash when doing a lot of fetching in ZScript
The crash occurs when the function accumulates more than 255 integer constants. I guess that the opcode to read a constant isn't working properly.
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49067
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Crash when doing a lot of fetching in ZScript
Fixed. The check for handling this was wrong for one particular opcode that got used here.
Re: Crash when doing a lot of fetching in ZScript
Amazing. Thank you!
Is there an actual limit of how many variables one can have? And would 170 assignment operations almost each tic lag out?
Is there an actual limit of how many variables one can have? And would 170 assignment operations almost each tic lag out?
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49067
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Crash when doing a lot of fetching in ZScript
Assignment operations are cheap. The biggest time waster in your code would be the (native) lookup of the actual CVARs and not the VM code.
Regarding limits. The available resources per function are:
- 32767 integer constants
- 32767 string constants
- 32767 float constants
- 32767 address constants (this includes all function addresses, RNGs or other native resources being referenced.)
- 256 integer registers
- 256 floating point registers
- 256 string registers
- 256 address registers
Note that registers and local variables are not equivalent. Some registers are needed for intermediate results and arrays and structs are allocated on the stack, not in registers.
Regarding limits. The available resources per function are:
- 32767 integer constants
- 32767 string constants
- 32767 float constants
- 32767 address constants (this includes all function addresses, RNGs or other native resources being referenced.)
- 256 integer registers
- 256 floating point registers
- 256 string registers
- 256 address registers
Note that registers and local variables are not equivalent. Some registers are needed for intermediate results and arrays and structs are allocated on the stack, not in registers.
Re: Crash when doing a lot of fetching in ZScript
This is very useful to know. Thank you once again.
- Major Cooke
- Posts: 8175
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: Crash when doing a lot of fetching in ZScript
I've made a dedicated page to ensure this information isn't lost.
However, by native resources, is that just functions or are properties included?
However, by native resources, is that just functions or are properties included?
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49067
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Crash when doing a lot of fetching in ZScript
That's local resources per function. Classes are stored elsewhere in memory and are not affected by this.
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: Crash when doing a lot of fetching in ZScript
Are these limits for every named or anonymous function being called?
Like, if I have a A_ABC() inside which there's a A_XYZ() call, do each of them have their own limit (i.e., I can have up to 256 address registers in A_XYZ without using up A_ABC's limit)
Also, is an "address register" like a pointer?
Like, if I have a A_ABC() inside which there's a A_XYZ() call, do each of them have their own limit (i.e., I can have up to 256 address registers in A_XYZ without using up A_ABC's limit)
Also, is an "address register" like a pointer?
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49067
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Crash when doing a lot of fetching in ZScript
Each function gets its own set of registers. And yes, an address register is effectively a pointer.