#Custom creature AI update exception that i can't seem to figure from what it's causing it (Fisobs)
1 messages · Page 1 of 1 (latest)
Would be useful to know what exactly throws the null reference exception, which can be obtained from logging everything that's referenced in CoordinateCost() and may cause a NRE.
Base game errors in such fundamental functions are very commonly something being passed into as null that's not intended to be, e.g. a room not being baked properly or an invalid attribute being assigned.
hm i see
let me see if i can overwrite that method to print out what is wrong
@abstract mica like this?
pretty much, but with extra logs for everything that can cause a NRE in CoordinateCost
and what those would be in my case?
everywhere where either a . or a [ is used to access a member of a variable in base game's version of CoordinateCost
can't actually open the codebase myself rn
oh well, i can show the function for u
hmm
maybe its the forbiddenNode that is null? or smth else here i can't figure out? maybe the coord?
figuring this out is what logging is for
forbiddenNode being null wouldn't matter though because there's a null check here
yeah it must be coord
let me run the game
hm, idk if this is bad or not, btw i spawned my creature in a arena for testing @abstract mica
shows coord isn't null, hence you need more logs to find out what is null 
hm hmm
maybe 'this.realizedRoom.aimap'?
i'd really just log pretty much everywhere where a . is used
it's a temporary log, you can afford to make it spammy
so now with this, @abstract mica, what can you think of my code that is making the aimap null?
ah ofc u had to go offline now grr
:P
might be or is certainly null, and is it null specifically in the context where that code would be reached?
yeah, i put the hook before orig so it would run first, then the vannila code
and it seems like it is
since else the game would freeze and log stuff in the console
for example, aimap being null won't matter if InThisRealizedRoom() returns false, since the code path that requires aimap never gets reached
this doesn't make sure that aimap being null even matters
the thing you want to know is what causes the null reference exception, and for that the two conditions are being null and having an attribute referenced
this can only establish that it's null and not that the code that references the attribute is reached
hm, so how do i do that?
more logging 
if InThisRealizedRoom() returns true in the function, it will return true in the log
if it returns false in the function, it will return false in the log
hm, so i just hook it up and see if it returns true or false in a situation i know it's being called from CoordinateCost?
as I said, you can just spam the log just fine, and you can log as many values as you want at a given time
you can just obtain all information about what everything used in the function is to theoretically trace what path the code takes
the low effort solution I typically had is just e.g. Logger.LogMessage($"{self.forbiddenNode} {coord} {self.forbiddenNode?.value} {self.InThisRealizedRoom(coord)} {self.realizedRoom} <other potential info>"); expanded to cover everything that can matter, whether it's targets of nullref or what determines the path the code takes
then use that to trace what path the code takes and find the first instance of a null that lies in a path the code actually takes, which is the cause of the null reference exception
and then repeat logging with assignments with code related to that variable to find what causes it to take on an unexpected value