Project Zomboid

Project Zomboid

Firearms
Br0u 6 月 11 日 下午 2:08
[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.
< >
正在显示第 1 - 8 条,共 8 条留言
forsaken1013 6 月 11 日 下午 9:15 
i couldn't shoot any firearms since last update, your fix works for me on version B42.9, thanks a lot!
Guardian 6 月 11 日 下午 9:45 
How do I apply the new code?
Guardian 6 月 11 日 下午 10:15 
引用自 Guardian
How do I apply the new code?
nvm
LambVORTEX 6 月 11 日 下午 11:50 
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 6 月 12 日 上午 12:45 
Thank you very much, your solution to the problem helped a lot, everything is working now)
Deju 6 月 12 日 上午 2:21 
How do you add this fix to the mod?
Dexion 6 月 12 日 上午 3:51 
引用自 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 !)
最后由 Dexion 编辑于; 6 月 12 日 上午 3:52
Deju 6 月 12 日 上午 5:32 
引用自 Dexion
引用自 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!
< >
正在显示第 1 - 8 条,共 8 条留言
每页显示数: 1530 50