Page 1 of 1

Identify the callback culprit?

Posted: Fri Apr 28, 2017 2:26 pm
by visage
I keep on running into an issue where some "on damage taken" callback is returning a number rather than a hash and thus causing all sorts of things to break horribly. I assume this is the fault of one or another of the mods I have installed.

Is there a reasonable way for me to track down which callback it is or am I stuck with: code-diving; and getting a savefile into that state and then using the debug tools to start disabling effects until I've isolated what's going on?

Re: Identify the callback culprit?

Posted: Fri Apr 28, 2017 3:10 pm
by Micbran
Does it not give you a stack trace?

Re: Identify the callback culprit?

Posted: Fri Apr 28, 2017 3:37 pm
by visage
Sure it does, but the callback has already returned its value.

Re: Identify the callback culprit?

Posted: Fri Apr 28, 2017 7:51 pm
by visage
To elaborate...

The traceback:

Code: Select all

[LOG]	#UID:16013:0#Shadow hits #fbd578#Raze Corona Gunner#LAST# for #aaaaaa#(17 to psi shield)#LAST# damage.
Lua Error: /data/damage_types.lua:477: attempt to index local 'ret' (a number value)
	At [C]:-1 __index
	At /data/damage_types.lua:477 defaultProjector
	At /data/damage_types.lua:742 projector
	At /data/damage_types.lua:1127 projector
	At /engine/interface/ActorProject.lua:420 projectDoAct
	At /engine/interface/ActorProject.lua:508 projectDoStop
	At /engine/Projectile.lua:230 act
	At /engine/GameEnergyBased.lua:129 tickLevel
	At /engine/GameEnergyBased.lua:64 tick
	At /engine/GameTurnBased.lua:51 tick
	At /mod/class/Game.lua:1386 
The code around line 477 in damage_types is:

Code: Select all

		if target.iterCallbacks then
			for cb in target:iterCallbacks("callbackOnTakeDamage") do
				local ret = cb(src, x, y, type, dam, state)
				if ret then
					if ret.dam then dam = ret.dam end
					if ret.stopped then return ret.stopped end
				end
			end
		end
So, one solution to my problem of identifying the culprit would be for there to be a line I could insert inside the for loop that would log an identifier for the callback.

Re: Identify the callback culprit?

Posted: Wed May 03, 2017 3:18 am
by visage
Unless I'm misreading this, there's a bug in Forcefield:

Code: Select all

	callbackOnTakeDamage = function(self, t, src, x, y, damtype, dam, tmp)
		local ff = self:isTalentActive(t.id)
		if not ff then return dam end
		local total_dam = dam
		local absorbable_dam = t.getResist(self,t) / 100 * total_dam
		local guaranteed_dam = total_dam - absorbable_dam
		return {dam=guaranteed_dam}
	end,
If the callback is called while the talent isn't active, it returns the damage rather than a hash containing the damage. This causes line 477 in damage_types to blow up.

...and changing that line does in fact seem to resolve my issue.