
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM |
FB II COMPILER
Check for valid XREF@
Here's another tool. It will be a pain to use, but if it finds the problem it will be worth it. First copy this FN to the top of your code.
LOCAL MODE
LOCAL FN eXchequer(XREFHandle&,lastXREFdim%,elemSize%,element1%,element2%)
'XREFHandle& is the long integer to which the XREF@
' statement is linked (it has the same name as your array).
'elemSize = 2 for short integer(%), 4 for long integer(&), etc.
' If no size (0) is passed, short integer (2) will be used.
'lastXREFdim is the number used in the XREF@ statement,
' or the last one if there are 2 dimensions.
'element1 is the first coordinate of a call to a two-dimension array.
' If there is only one dimension, pass _none.
'element2 is the second or only coordinate of a call to an array.
'-----------------------------------------
'This FN will beep and drop into the debugger if the elements
' addressed are outside the handle or the handle is invalid.
DIM size&
IF elemSize% = 0 THEN elemSize% = 2
LONG IF XREFHandle&
size& = FN GETHANDLESIZE(XREFHandle&)
LONG IF size& >= (element1%*(lastXREFdim%+1)+(element2%+1))*elemSize%
EXIT FN 'All okay
END IF
END IF
BEEP:BEEP
'******************************************************
'*** The elements passed are outside of the handle, ***
'*** or the handle is invalid. ***
'******************************************************
TRON BREAK
END FN
Then find every place in your code where you write to an XREF@ array, (i.e., myXREFarray%(var) = something) and paste this line just before it:
FN eXchequer(XREFHandle&,lastXREFdim,elemSize,_none,elementNumber)
Select each parameter and paste (or type) in the appropriate vars or numbers (see the REMs in the code). Just this exercise could turn up something. FN eXchequer works for both 1- and 2-dimensional arrays. When 2, replace "_none" with the _first_ element var.
Run your code. If it works smoothly, but you still get corrupted data, you can be reasonably certain it's not from writing outside the handles or using pointers in place of handles.
If it drops you into the debugger, first check the value of size&. If it's 0, you have an invalid handle--you may have passed a pointer instead. Note the parameters passed, and step out of FN eXchequer. Make sure the parameters were correct. If so, you will be looking at where you are about to corrupt memory.
I hope this will turn something up. It's untested, so please observe the usual caveats.
|