11-16-2010, 03:09 PM
I seem to be having some issues trying to use a 2D array of Strings in some cases, but unfortunately I don't seem to be able to figure out what they are. A piece of code which seems to work fine in isolation fails when I put it into my main program with screen corruption and a crash. Is a 2D array of Strings 'bad form' for some reason?
In the end I replaced it with a 2D array of UBYTEs instead which worked okay (and was probably less wasteful, tbh - I was only storing single characters anyway). If I figure out a decent way to reproduce the crash without it being embedded in a huge chunk of other stuff then I'll post it. It could well be something silly that I've done elsewhere in the program.
While I'm here, could someone clarify what is okay to declare within a SUB? I don't seem to have any problems declaring normal variables (e.g. DIM test AS UBYTE) within a SUB, but I seem to have crash issues if I try to declare and use an array (e.g. DIM test(2,2) AS UBYTE). Is it actually legal to try and do that?
This code, for example, crashes unless I move the UBYTE array outside of the SUB:
Sorry if the answer here is obvious, I'm still getting used to how things work.
In the end I replaced it with a 2D array of UBYTEs instead which worked okay (and was probably less wasteful, tbh - I was only storing single characters anyway). If I figure out a decent way to reproduce the crash without it being embedded in a huge chunk of other stuff then I'll post it. It could well be something silly that I've done elsewhere in the program.
While I'm here, could someone clarify what is okay to declare within a SUB? I don't seem to have any problems declaring normal variables (e.g. DIM test AS UBYTE) within a SUB, but I seem to have crash issues if I try to declare and use an array (e.g. DIM test(2,2) AS UBYTE). Is it actually legal to try and do that?
This code, for example, crashes unless I move the UBYTE array outside of the SUB:
Code:
test()
SUB test
DIM xpos as UBYTE
DIM ypos as UBYTE
DIM scrdata(22, 32) AS UBYTE
CLS
FOR ypos = 0 TO 21
FOR xpos = 0 TO 31
scrdata(ypos, xpos) = 65
NEXT xpos
NEXT ypos
PRINT "Done."
PAUSE 0
CLS
FOR ypos = 0 TO 21
FOR xpos = 0 TO 31
PRINT AT ypos, xpos; CHR(scrdata(ypos, xpos))
NEXT xpos
NEXT ypos
END SUB
Sorry if the answer here is obvious, I'm still getting used to how things work.