So while doing a check for conditions using a Do While Loop, I came upon something that put me into a tailspin.
My goal is to analyze a users input and compare their character to a reference character, so I use a CharacterMap to store all their input.
(The commented out code below is the Do While Loop)
CharacterMap is a list of points that I am evaluating to see if they cross each other. I iterate through the points, and if the points match, I add markers (the .hasCross). This code then takes the start of a .hasCross situation and puts all the points in-between into a smaller list, so I can analyze the properties of those points. (to see if the shape is round enough to qualify as a loop)
Was working great, and then on one character I started getting some very strange behavior in my program.
You can see that I added q=638, so that I could freeze the program there during a debug session. While watching the code line by line, when q = 648 (I added the 649 to see if 648 was the problem), and EndPoint clearly not meeting the parameters for the Do While Loop, code continued OUT of the Do While Loop. (size of this particular Map was 1440 or so)
Eventually, I changed it to the If.. Next instead, and the code works great again.
But, why would this have happened? Is there a memory issue that Do While Loops have? Is there something basic in the code comparison I'm missing? (I don't think so, as it worked for many test cases before, including loops within that test character)
Anyone else have this kind of error?
Ross
(sorry about the bad variable names (CrossPointMPOrder and OriginalMaOrder, this is because when reading a Map back in from a file, I put it back into the order that it was saved, and I discoverd that I can't parse out MapOrder by itself when looking for it as a string inside each element... changing the name for each of the other two fixed that! Poor I know, but too much time invested in creating the original character files!)
My goal is to analyze a users input and compare their character to a reference character, so I use a CharacterMap to store all their input.
(The commented out code below is the Do While Loop)
CharacterMap is a list of points that I am evaluating to see if they cross each other. I iterate through the points, and if the points match, I add markers (the .hasCross). This code then takes the start of a .hasCross situation and puts all the points in-between into a smaller list, so I can analyze the properties of those points. (to see if the shape is round enough to qualify as a loop)
Was working great, and then on one character I started getting some very strange behavior in my program.
You can see that I added q=638, so that I could freeze the program there during a debug session. While watching the code line by line, when q = 648 (I added the 649 to see if 648 was the problem), and EndPoint clearly not meeting the parameters for the Do While Loop, code continued OUT of the Do While Loop. (size of this particular Map was 1440 or so)
Eventually, I changed it to the If.. Next instead, and the code works great again.
But, why would this have happened? Is there a memory issue that Do While Loops have? Is there something basic in the code comparison I'm missing? (I don't think so, as it worked for many test cases before, including loops within that test character)
Anyone else have this kind of error?
Ross
(sorry about the bad variable names (CrossPointMPOrder and OriginalMaOrder, this is because when reading a Map back in from a file, I put it back into the order that it was saved, and I discoverd that I can't parse out MapOrder by itself when looking for it as a string inside each element... changing the name for each of the other two fixed that! Poor I know, but too much time invested in creating the original character files!)
B4X:
For q = i + 1 To CharacterMap.Size - 1
If StartPoint.CrossPointMpOrder = EndPoint.originalMaOrder AND StartPoint.originalMaOrder = EndPoint.CrossPointMpOrder _
AND EndPoint.hasCross = True Then
j = q
q = CharacterMap.Size-1
Exit
Else
If EndPoint.hasCross AND Not(boolLoopExists) Then
startmarker = q
boolLoopExists = True
End If
TestCharacter.Put(TestCharacter.Size, EndPoint)
End If
EndPoint= CharacterMap.GetValueAt(q)
Next
' Do While StartPoint.CrossPointMpOrder <> EndPoint.originalMaOrder AND StartPoint.originalMaOrder <> EndPoint.CrossPointMpOrder _
' AND EndPoint.hasCross <> True
' TestCharacter.Put(TestCharacter.Size, EndPoint)
' If q = 638 Then
' Dim answer
' q = 649
' End If
' q = q+1
' If q > CharacterMap.Size -1 Then
' Exit
' Else
' EndPoint = CharacterMap.GetValueAt(q)
' End If
' Loop
'put a box around the test character