Project Zomboid

Project Zomboid

Firearms
Br0u 11 Jun @ 2:08pm
[h1]Fix: Stack Overflow in Firearms B42 (attackHookFirearms Infinite Loop)[/h1]
Fix: Stack Overflow in Firearms B42 (attackHookFirearms Infinite Loop)

Problem:
The mod Firearms B42 crashes the game at startup due to a stack overflow caused by recursive Lua hook setup.
Error log points to:
Firearms_ISReloadWeaponAction.lua line #13

Bugged Code (Before):
Events.OnGameBoot.Add(function() Hook.Attack.Remove(ISReloadWeaponAction.attackHook) Hook.Attack.Add(ISReloadWeaponAction.attackHookFirearms) ini original_attackHook = ISReloadWeaponAction.attackHook ISReloadWeaponAction.attackHook = ISReloadWeaponAction.attackHookFirearms -- ⚠️ Causes recursion end)

Fixed Code:
Events.OnGameBoot.Add(function() original_attackHook = ISReloadWeaponAction.attackHook scss Hook.Attack.Remove(ISReloadWeaponAction.attackHook) Hook.Attack.Add(ISReloadWeaponAction.attackHookFirearms) end)

Result:

Game no longer crashes.

Hook is safely registered.

Tested on Project Zomboid v41.78.

If you're a mod user or developer encountering this crash, apply this fix to avoid recursion and stack overflow issues.
< >
Showing 1-8 of 8 comments
i couldn't shoot any firearms since last update, your fix works for me on version B42.9, thanks a lot!
Guardian 11 Jun @ 9:45pm 
How do I apply the new code?
Guardian 11 Jun @ 10:15pm 
Originally posted by Guardian:
How do I apply the new code?
nvm
LambVORTEX 11 Jun @ 11:50pm 
This is silly and I love it. Thanks for the patch... Not sure why it was tested only on B41 but I'm sure the bug is also present there.
badlam 12 Jun @ 12:45am 
Thank you very much, your solution to the problem helped a lot, everything is working now)
Deju 12 Jun @ 2:21am 
How do you add this fix to the mod?
Dexion 12 Jun @ 3:51am 
Originally posted by Deju:
How do you add this fix to the mod?

Have to search by myself but find it.

------> Go to the mod directory where PZ is installed.
Don't know which version you use, i'm on 42.9 so for me it's 42.9 folder in the following path.

"Yourletterdrive":\SteamLibrary\steamapps\workshop\content\108600\2256623447\mods\Firearms\42.9\media\lua\shared\Firearms\TimedActions


------> SAVE THE ORIGINAL FILE IN CASE OF MISTAKE
Open "Firearms_ISReloadWeaponAction.lua" with a text editor and replace the section at the end by the new one like Br0u said.

don't have exactly the same "before code" as above, my code in was :

Events.OnGameBoot.Add(function()
Hook.Attack.Remove(ISReloadWeaponAction.attackHook);
Hook.Attack.Add(ISReloadWeaponAction.attackHookFirearms) -- add our new callback

-- store the original function.
original_attackHook = ISReloadWeaponAction.attackHook
-- overwrite is probably redundant at this point, but best done just in case.
ISReloadWeaponAction.attackHook = ISReloadWeaponAction.attackHookFirearms
end)

And after replacing it all by the "after code" above, no error anymore, so worth it to try.
---------------------------

It's working in B42, thank you so much !
i was attacked by bandits and can't shoot, solve my problem (and their too :'D !)
Last edited by Dexion; 12 Jun @ 3:52am
Deju 12 Jun @ 5:32am 
Originally posted by Dexion:
Originally posted by Deju:
How do you add this fix to the mod?

Have to search by myself but find it.

------> Go to the mod directory where PZ is installed.
Don't know which version you use, i'm on 42.9 so for me it's 42.9 folder in the following path.

"Yourletterdrive":\SteamLibrary\steamapps\workshop\content\108600\2256623447\mods\Firearms\42.9\media\lua\shared\Firearms\TimedActions


------> SAVE THE ORIGINAL FILE IN CASE OF MISTAKE
Open "Firearms_ISReloadWeaponAction.lua" with a text editor and replace the section at the end by the new one like Br0u said.

don't have exactly the same "before code" as above, my code in was :

Events.OnGameBoot.Add(function()
Hook.Attack.Remove(ISReloadWeaponAction.attackHook);
Hook.Attack.Add(ISReloadWeaponAction.attackHookFirearms) -- add our new callback

-- store the original function.
original_attackHook = ISReloadWeaponAction.attackHook
-- overwrite is probably redundant at this point, but best done just in case.
ISReloadWeaponAction.attackHook = ISReloadWeaponAction.attackHookFirearms
end)

And after replacing it all by the "after code" above, no error anymore, so worth it to try.
---------------------------

It's working in B42, thank you so much !
i was attacked by bandits and can't shoot, solve my problem (and their too :'D !)

Appreciate it!
< >
Showing 1-8 of 8 comments
Per page: 1530 50