Skip to content

Crash when opening PDA due to unjam_motion_mark.script #736

@SUKUNA-AI

Description

@SUKUNA-AI

Summary

Game crashes when opening/drawing the PDA, likely because unjam_motion_mark.script assumes the actor's active item is always a weapon.

When the active item is PDA/device/non-weapon, this line crashes:

db.actor:active_item():cast_Weapon():SetMisfire(false)

The script does not check whether active_item() exists and whether it can be cast to weapon.

Environment

  • Game: S.T.A.L.K.E.R. Anomaly / GAMMA
  • GAMMA version: 0.9.5 update after May 15 2026
  • Engine: X-Ray Monolith v1.5.3
  • Modded Exes: MT-TEST version 2026.05.15
  • Executable: anomalydx11avx.exe
  • Location where reproduced: Garbage
  • Trigger: opening/drawing PDA

Reproduction steps

  1. Start/load a game.
  2. Go to Garbage / Свалка.
  3. Equip normal weapons.
  4. Open/draw PDA.
  5. Game crashes with Lua runtime error.

Actual result

The game crashes with:

[LUA] d:/anomaly\gamedata\scripts\unjam_motion_mark.script:4: attempt to index a nil value

FATAL ERROR

Function      : CScriptEngine::lua_pcall_failed
Description   : fatal error

LUA error:
d:/anomaly\gamedata\scripts\unjam_motion_mark.script:4: attempt to index a nil value

Stack trace points to:

unjam_motion_mark.script(4)
axr_main.script(284) : make_callback
_g.script(118) : SendScriptCallback
_g_patches.script(418)

The uploaded log confirms the crash path: unjam_motion_mark.script(4) is called through SendScriptCallback, then the game raises CScriptEngine::lua_pcall_failed and exits with fatal Lua error.

Active conflicting file in MO2

In MO2 Data tab, active script path:

Data\gamedata\scripts\unjam_motion_mark.script

is provided by:

92- Vityaz Replacer - Blackgrowl

There are many other mods shipping the same script, but the winning/active one in MO2 was:

92- Vityaz Replacer - Blackgrowl

Original script

-- Clear jam mid animation with motion marks
function actor_on_hud_animation_mark(state, mark)
	if mark == "clear_jam" then
		db.actor:active_item():cast_Weapon():SetMisfire(false)
	end
end

function on_game_start()
	RegisterScriptCallback("actor_on_hud_animation_mark", actor_on_hud_animation_mark)
end

Suspected cause

actor_on_hud_animation_mark can be fired while the actor's active item is not a weapon, for example PDA/device/empty hands.

The script assumes this chain is always valid:

db.actor:active_item():cast_Weapon():SetMisfire(false)

But if:

db.actor == nil
db.actor:active_item() == nil
active_item is not a weapon
cast_Weapon() returns nil

then line 4 crashes with:

attempt to index a nil value

Temporary workaround / local hotfix

I created a small MO2 override mod placed lower than weapon reanimation mods:

SUKUNA - Safe unjam_motion_mark hotfix

with this safe version:

-- Safe unjam motion mark handler.
-- Fixes crash when actor_on_hud_animation_mark fires while active item is not a weapon
-- e.g. PDA / device / empty hands.

local function safe_clear_misfire()
	if not db or not db.actor then
		return
	end

	local item = db.actor:active_item()
	if not item then
		return
	end

	local weapon = nil

	local ok_cast = pcall(function()
		weapon = item:cast_Weapon()
	end)

	if not ok_cast or not weapon then
		return
	end

	pcall(function()
		weapon:SetMisfire(false)
	end)
end

function actor_on_hud_animation_mark(state, mark)
	if mark ~= "clear_jam" then
		return
	end

	safe_clear_misfire()
end

function on_game_start()
	RegisterScriptCallback("actor_on_hud_animation_mark", actor_on_hud_animation_mark)
end

Expected fix

Add nil/type guards before calling:

SetMisfire(false)

At minimum:

function actor_on_hud_animation_mark(state, mark)
	if mark ~= "clear_jam" then
		return
	end

	if not db or not db.actor then
		return
	end

	local item = db.actor:active_item()
	if not item then
		return
	end

	local weapon = item:cast_Weapon()
	if not weapon then
		return
	end

	weapon:SetMisfire(false)
end

A pcall around cast_Weapon() may be safer if some active items do not support this call cleanly.

Notes

This does not appear to be a PDA bug directly. PDA only triggers the animation/callback chain.

The crash is caused by unjam_motion_mark.script assuming the active item is always a weapon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions