ZDoom / Raze

Build engine port backed by GZDoom tech. Currently supports Duke Nukem 3D, Blood, Shadow Warrior, Redneck Rampage and Powerslave/Exhumed.
691 stars 59 forks source link

[BUG] [Duke 3D] Ripper ammo can go negative or crash game when cl_weaponswitch=0 #762

Closed prg318 closed 1 year ago

prg318 commented 1 year ago

Raze version

1.6pre+2080+gc6b3cf3e0

Which game are you running with Raze?

Duke Nukem 3D

What Operating System are you using?

Linux x86_64

Please describe your specific OS version

Arch Linux x64

Relevant hardware info

AMD 5700 XT

Have you checked that no other similar issue already exists?

A clear and concise description of what the bug is.

For this issue to occur, "cl_weaponswitch" must be set to "0". If you hold down fire button with the ripper equipped, the ripper ammo will either proceed to go into negative values and continue firing (if the default status bar HUD is hidden) or the game will crash with the following error message in the logs (if the default status bar HUD is shown):

VM execution aborted: array access out of bounds. Negative current index = -3

Called from DukeStatusBar.DrawWeaponNum at raze.pk3:zscript/games/duke/ui/sbar_d.zs, line 362
Called from DukeStatusBar.DrawWeaponAmounts at raze.pk3:zscript/games/duke/ui/sbar_d.zs, line 390
Called from DukeStatusBar.Statusbar at raze.pk3:zscript/games/duke/ui/sbar_d.zs, line 437
Called from DukeStatusBar.UpdateStatusBar at raze.pk3:zscript/games/duke/ui/sbar_d.zs, line 480

Steps to reproduce the behaviour.

Explain how to reproduce

  1. Launch any episode of duke3d
  2. Open the console, type "cl_weaponswitch 0"
  3. Also enter "give weapons"
  4. Equip the ripper and hold down the fire button until no rounds are left.

Your configuration

# To crash the game use hud_size 5 when reproducing this bug
hud_size 5
cl_weaponswitch 0

# To go into negative ammo, use hud_size 8 when reproducing this bug

Provide a Log

VM execution aborted: array access out of bounds. Negative current index = -3

Called from DukeStatusBar.DrawWeaponNum at raze.pk3:zscript/games/duke/ui/sbar_d.zs, line 362 Called from DukeStatusBar.DrawWeaponAmounts at raze.pk3:zscript/games/duke/ui/sbar_d.zs, line 390 Called from DukeStatusBar.Statusbar at raze.pk3:zscript/games/duke/ui/sbar_d.zs, line 437 Called from DukeStatusBar.UpdateStatusBar at raze.pk3:zscript/games/duke/ui/sbar_d.zs, line 480

coelckers commented 1 year ago

What's a "ripper"? Duke does not have a weapon with that name. Please always use official names to avoid misunderstanding.

I fixed the HUD display but since no weapon caused a crash for me I'm not sure how to prevent the counter from becoming negative.

prg318 commented 1 year ago

"Ripper" is the frequently used name for the "Chaingun Cannon" in Duke3D (slot 4). FWIW I can reproduce the negative ammo issue with any config using the following:

map e1l1
give weapons
cl_weaponswitch 0
hud_size 8
slot 4
+fire

It doesn't crash the game, it simply allows you to fire your slot 4 weapon when you shouldn't be able to. If you have the default hud_size, it will crash the level with the log file provided in the original post.

Let me know if anything else is unclear

coelckers commented 1 year ago

I can't get it to crash but it continues shooting with the ammo numbers getting ever more negative.

coelckers commented 1 year ago

fixed in dc60c643c98693d2a29cf6d2f04cd1bb18f15bd6