From 06d5c4f7cd63cf8ceba6b6438bfb093033a7fad4 Mon Sep 17 00:00:00 2001 From: rockdtben Date: Tue, 26 Jul 2011 15:26:06 +0000 Subject: [PATCH] fixed a runtime error auto_use_power only shows up in the master_controller following code: *************** for(var/obj/machinery/machine in machines) if(machine) machine.process() if(machine && machine.use_power) machine.auto_use_power() *************** on the second line it checks if machine exists. If it doesn't exit it would go to the next machine. So it is not null at this point. then it calls machine.process()... on the fourth line it cehcks again if the machine exists. Then it calls machine.auto_use_power() So at this point the machine has been checked twice for existence. Now moving into aut_use_power() proc ********************* /obj/machinery/proc/auto_use_power() if(!powered(power_channel)) return 0 if(src.use_power == 1) use_power(idle_power_usage,power_channel) else if(src.use_power >= 2) use_power(active_power_usage,power_channel) return 1 ********************* This calls powered() on the second line. now stepping into powered() proc ************************** /obj/machinery/proc/powered(var/chan = EQUIP) var/area/A = src.loc.loc // make sure it's in an area if(!A || !isarea(A)) return 0 // if not, then not powered return A.master.powered(chan) // return power status of the area ************************** the second line "var/area/A = src.loc.loc" line 26 in power.dm is what caused the problem. It is asking for the location. src.loc appears to be null. The reason why this call keeps happening and doesn't stop is because the object itself exists but its location does not. So my final analysis is that src.loc == null and calling loc on src.loc gives us a runtime error since src.loc.loc == null.loc and null cannot call loc. runtime error: Cannot read null.loc proc name: powered (/obj/machinery/proc/powered) source file: power.dm,26 usr: null src: Emitter (/obj/machinery/emitter) call stack: Emitter (/obj/machinery/emitter): powered(1) Emitter (/obj/machinery/emitter): auto use power() /datum/controller/game_control... (/datum/controller/game_controller): process() /datum/controller/game_control... (/datum/controller/game_controller): process() git-svn-id: http://tgstation13.googlecode.com/svn/trunk@1932 316c924e-a436-60f5-8080-3fe189b3f50e --- code/modules/power/power.dm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/modules/power/power.dm b/code/modules/power/power.dm index a00d4b8329..b937333a61 100644 --- a/code/modules/power/power.dm +++ b/code/modules/power/power.dm @@ -23,6 +23,10 @@ // defaults to equipment channel /obj/machinery/proc/powered(var/chan = EQUIP) + + if(!src.loc) + return 0 + var/area/A = src.loc.loc // make sure it's in an area if(!A || !isarea(A)) return 0 // if not, then not powered