I ran into similar problems that made me crazy.
I had code that suddenly started dying when it hit certain statements. And it appeared to be somewhat related to where the lines of code sat.
In one case, if I put a do nothing statement like assigning a string to a variable that isn't used, the line where the program failed would shift.
I eventually figured out that the issue was definitely due to UDTs within UDTs that are in an array.
The type setup looks like this:
//
// an X-Y point
//
TYPE aPoint
fX AS float
fY AS float
ENDTYPE
TYPE tBlackHole
evtHor AS float
gravHor AS float
isAt AS aPoint // the UDT within the UDT
fore_id AS integer
fore_ang AS float
back_id AS integer
back_ang AS float
ENDTYPE
global dim g_BHs[5] AS tBlackHole
If I passed the 'isAt' element in a black hole directly into a function call, the results would be fine the first time a level is played. But the second time (after you've fallen into the black hole or gone off the edge), the results would be scrambled.
This fails:
bh_dst# = DistanceBetweenPoints(thePlayer.isAt,g_BHs[bh_ind].isAt)
And this fixed the problem:
g_BH AS tBlackHole
for bh_ind=0 to theGame.bhCount - 1
// make a copy to work with
g_BH = g_BHs[bh_ind]
bh_dst# = DistanceBetweenPoints(thePlayer.isAt,g_BH.isAt)
....
next bh_ind
I was trying to figure out a simple example that would show the problem (a small extract from my project just doesn't happen easily now).
Thank you, MikeMax, for coming up with one.
And I do hope this is fixed in the next version.
Oh, my black hole works very nicely. I had fun figuring the right equations and forces/impulses, etc. to get the gravity well and event horizon working right.
Cheers,
Ancient Lady