I get a
runtime error: Cannot read null.hands_free
error when trying to read src.hands_free
, even though src shouldn't be null and a check has been done first to ensure that it isn't.Code Snippet (if applicable) to Reproduce Problem:
/mob/human/proc/set_hand(obj/item/I, hand=src.hand)
if(!src||!src.hands_free||src.lying)return //This line causes an error
//...
/obj/item/MouseDrop(over_object)
var/mob/human/user=usr
if(!istype(user)||!(src in view(1))) return ..()
if(istype(over_object, /obj/HudUI/hand))
var/obj/HudUI/hand/H=over_object
user.set_hand(src, H.hand)
user.Update()
Expected Results:
The expression is evaluated and the proc returns if needed. Even if src was null for some reason., the !src check should prevent an error.
Actual Results:
BYOND seems to think src is null even though the given value for src in the error message below proves that it isn't.
runtime error: Cannot read null.hands_free proc name: set hand (/mob/human/proc/set_hand) source file: human.dm,239 usr: Nickr5 (/mob/human/native) src: Nickr5 (/mob/human/native) call stack: Nickr5 (/mob/human/native): set hand(the tomahawk (/obj/item/weapon/axe), 0) the tomahawk (/obj/item/weapon/axe): MouseDrop(the hand (/obj/HudUI/hand), the grass (3,1,1) (/turf/grass), null, "mapwindow.map", "mapwindow.map", "icon-x=15;icon-y=17;left=1;scr...")
Does the problem occur:
Every time? Or how often? Every time.
In other games? Not as far as I can tell. I wasn't able to duplicate the problem in a separate project.
In other user accounts? Not sure.
On other computers? Not sure.
When does the problem NOT occur?
When one of the workarounds below are used.
Workarounds:
Replacing the problematic line with this causes everything work fine:
if(!src.vars.Find("hands_free")||!src.hands_free||src.lying)return
Placing
ASSERT(src)
at the beginning of the set_hand() proc also fixes the probem.
Of course I could be wrong.
Though it makes sense the ASSERT makes it escape properly, ASSERT basically translating to if (!value) return.
edit: crap. !cake would return true if cake was null, effectively ending the check... I was tired. =\