Odd list behaviour - objects not being cast
BlitzMax Forums/BlitzMax Programming/Odd list behaviour - objects not being cast
| ||
I've got this really odd problem with my code that I've been attempting to nail down all day, but as yet I can't determine the exact cause, or even produce a working sample. The error is in this chunk of code, part of a collision detection routine. 'ask the collision grid for the nearby objects Local nearObjects:TList = fGrid.GetNearObjects(obj.GetPosition()) Local testLink:TLink = nearObjects.FirstLink() Local testObj:TFryWorldObject Local collisionFound:Int = False While Not collisionFound And testLink testObj = TFryWorldObject(testLink.Value()) If Not testObj Then Print "NOT FOUND! ERROR!" If obj <> testObj And obj.IsColliding(testObj) Then collisionFound = True End If testLink = testLink.NextLink() Wend The GetNearObjects function returns a list of all TFryWorldObjects that are near a certain position. It does this by creating a list made up of the contents of the surrounding grid cells, and returning that list. However, often the testObj variable ends up Null, resulting in "NOT FOUND! ERROR!" being output from the program. What's most odd about this is that it does not produce the error at all if run in Debug mode, only in Release mode. Also, the error takes longer to occur if I include a GCCollect() in my main loop. If I pass the TList nearObjects as a parameter to the GetNearObjects function, rather than have it created by the function, the error does not occur. Alternatively, if I include these two lines after the call to GetNearObjects(), the error does not occur: For local o:TFryWorldObject = eachin nearObjects next I've tried all day, managing to track its manifestation down to this small part of code, but as I can't seem to reproduce it, I've hosted the whole warts-n-all module here: http://www.mediafire.com/?2z4zn3jqzo0 Build the modules, and run the Fry World.bmx program. It creates a small bucket and drops 100 spheres into it, which bounce around. This will work (but be slow) in Debug mode, and will display the error message in the output in release mode. Any help is greatly appreciated. Although I seem to be able to avoid the issue, I don't feel comfortable moving on much until I know what's caused it. Thanks. |
| ||
Ah, this behavior looks familiar. Awhile ago i ran at the similar problems when dealing with a local TList object via links. I kinda thought this bug was fixed in the latest versions of BlitzMax (didnt test it myself). Here is one topic about this bug and how to avoid it: http://www.blitzmax.com/Community/posts.php?topic=78957 |
| ||
Thanks Jur, seems that's exactly the problem. Quite the relief now knowing I can control it and it won't bite me later. |