Problems with Tlist.contains()

BlitzMax Forums/BlitzMax Programming/Problems with Tlist.contains()

Sonic(Posted 2006) [#1]
Hi I'm having trouble with a seemingly very odd bug in my code.

In my AI code, I have a Tlist representing lists of goals for the AI to perform. Occasionally, and seemingly randomly (every time I build it occurs at a different time - perhaps due to the random seed being different) the game gives me an 'attempt to access null object / method' error when I call:

If goallist.Contains(CONSTANT)

In the debugger, I can see that the right value is passed (a constant representing a goal) in the AI method which calls contains, and the list both exists and contains object[s]. However, the odd thing is that the link being tested in the Contains() method appears to be a TImageFont, and has a null value!

Any ideas at all about this, as I'm really scratching my head. It's being passed the correct stuff, but it thinks the object's value is null.


Robert Cummings(Posted 2006) [#2]
Wrong forum dude?


sswift(Posted 2006) [#3]
Provide more code.


FlameDuck(Posted 2006) [#4]
it thinks the object's value is null.
Or to put it more accurately, you think it isn't. I doubt the computer is making stuff up.

Anyway I understand you must have a valid graphics context before using LoadImageFont / SetImageFont. Maybe this is your problem?


Michael Reitzenstein(Posted 2006) [#5]
You can't use lists with integers - you'll need to use types to wrap them. This is a pain, yeah.

Contains uses compare and will sometimes crash if you have any null objects in the list, depending on the order.

This crashes:

Type Blah
End Type

Global List:TList = New TList
Global b:Blah = new Blah
List.AddLast( Null )
List.AddLast( b )

Print List.Contains( b )


This does not:

Type Blah
End Type

Global List:TList = New TList
Global b:Blah = new Blah
List.AddLast( b )
List.AddLast( Null )

Print List.Contains( b )



Sonic(Posted 2006) [#6]
Terribly sorry, didn't see my thread even got uploaded yesterday - my modem cut out and I didn't think it went through... I have just reposted it, and in the wrong forum again!

Oops... Moderators!

But this is what I posted, and has more info...

(Having said that I'm going to try the wrapper idea, as that seems to be the answer!)

------------------------------------------------------------------

I really am at my wits end with this problem, and I honestly don't know whether to post it here or in the bug reports!

I am using Bmax v1.10 on OSX 10.3, and don't yet want to move to the next version. But perhaps it could solve it, and I will try if nothing else works.

Basically, I am using a TList in my AI that contains goals (integer constants), and calling methods such as contains() to see which goals are further down the line. I only ever call these methods on a non-null, non-empty list with the integer constant as the 'value:Object' parameter.

It always crashes on contains(), with a 'null object / method' error. As far as I can tell (although I can't be certain as I usually run non-debug for speed. Another odd problem in this game is the huge difference in speed between these modes, something I didn't have with previous games, some more graphically intensive.)

What I can see in the debugger is that the correct values are held in the AI's methods, that the list exists and is not empty, and here's the killer...

... contains() seems to be looking for the existence of a TFont, and one with no 'value field'!

It doesn't always crash, different things seem to trigger it, even adding a completely unconnected line of code can solve it - until I type more (unrelated) code that throws it again. I haven't altered the AI code at all, besides double-checking all the references to the list in it.

Can anyone help me? I could really use some new lines of thinking, as I really have explored all avenues. Perhaps there is some kind of memory leak, and things are being overwritten, but I wouldn't know what to look for. I had no such problems in my scrolling platform game, and have used much the same framework.

Thanks,
Sonic.