Error from InstanceManager.lua (core file)

whoward69

DLL Minion
Joined
May 30, 2011
Messages
8,725
Location
Near Portsmouth, UK
Anybody any ideas what could be "nil"

Code:
Runtime Error: [string "Assets\UI\InstanceManager.lua"]:90: attempt to call method 'BuildInstanceForControl' (a nil value)

The line in question is

Code:
ContextPtr:BuildInstanceForControl( self.m_InstanceName, controlTable, self.m_ParentControl );

So is this trying to tell me that ContextPtr is nil (highly unlikely) or that there is no BuildInstanceForControl entry in the _metatable for ContextPtr, so other other (equally obscure) meaning????

:confused:
 
The error's actually well upstream of that point. If you screw up the ContextPtr declaration in the parent script (like if the calling routine is storing the context pointers in an array, and then you try to access an unset element of that array), that's the point where it'll finally fail; there's not a whole lot of intermediate error trapping.

Without knowing the script you're using that instance in, there's no easy way to debug it. I ran into this problem several times when creating the Mandala interface for my Mythology mod, and I pretty much had to debug the parent script by hand since FireTuner wouldn't give any more information than that.
 
I think it's even more convoluted than that.

The code works fine 90% of the time, but only throws the nil pointer error if there is a GenericPopup (or derivative - in this case the "You have researched Xyz" popup) on screen.

It seems that the Civ core wants to use the pop-up ContextPtr value and not the one associated with the context that the original InstanceManager:new() was called from

The code is basically

Code:
local g_PinManager = InstanceManager:new("Pin", "Anchor", Controls.PinContainer)

function OnSomeEvent()
    local instance = g_PinManager:GetInstance()
end

If some event fires and a generic pop-up is on screen the nil pointer error happens, otherwise it's fine, including other pop-ups (like DiploOverview) or overlays (like the TechTree).

Also calling it direct from FireTuner with a Generic pop-up works (but FireTuner forces the context so that doesn't surprise me)

It's all very weird
 
Back
Top Bottom