OK... it seems to be one of that strange horrible scenarios where everything just stops working in very weird ways. I had that with one or two projects before (on different computers, with different DBP versions and completely different codes).
Another function:
function pixelmap_swap(map, x1,y1, x2,y2)
off1 = 4*(x1 + pixelmap(map).w*y1)
off2 = 4*(x2 + pixelmap(map).w*y2)
rem Color
if pixelmap(map).mem > 0
col = memblock dword(pixelmap(map).mem, 12+off1)
write memblock dword pixelmap(map).mem, 12+off1, memblock dword(pixelmap(map).mem, 12+off2)
write memblock dword pixelmap(map).mem, 12+off2, col
else
...
endif
...
endfunction
It crashes with a memblock position out of range error for the
memblock dword(pixelmap(map).mem, 12+off2) part. So naturally I want to try to find out why exactly it crashes and output the function parameters at the start of the function in order to figure out what parameters cause the crash.
Well, what can I say, the output itself results in the crash not happening again. But no, that's not the end of the story, even putting this line at the start of the function:
tmp$ = "Swapping"
..solves the problem. However, other strings don't.
So what it comes down to is that this:
function pixelmap_swap(map, x1,y1, x2,y2)
tmp$ = "Swapping"
off1 = 4*(x1 + pixelmap(map).w*y1)
off2 = 4*(x2 + pixelmap(map).w*y2)
rem Color
if pixelmap(map).mem > 0
col = memblock dword(pixelmap(map).mem, 12+off1)
write memblock dword pixelmap(map).mem, 12+off1, memblock dword(pixelmap(map).mem, 12+off2)
write memblock dword pixelmap(map).mem, 12+off2, col
else
...
endif
...
endfunction
works fine, but this:
function pixelmap_swap(map, x1,y1, x2,y2)
tmp$ = "Test"
off1 = 4*(x1 + pixelmap(map).w*y1)
off2 = 4*(x2 + pixelmap(map).w*y2)
rem Color
if pixelmap(map).mem > 0
col = memblock dword(pixelmap(map).mem, 12+off1)
write memblock dword pixelmap(map).mem, 12+off1, memblock dword(pixelmap(map).mem, 12+off2)
write memblock dword pixelmap(map).mem, 12+off2, col
else
...
endif
...
endfunction
does not. I narrowed it down even further and got to the following conclusion:
Assigning tmp$ any string with 8 or more characters solves the problem. The program works. If I don't assign it any value, or use a string with 7 or less characters, I get the memblock position outside range error a few lines below. Unfortunately, this is not a joke.
Any input on what could cause these weird problems and how to solve them would be greatly appreciated.
Edit: Just an idea.. is it possible that assigning a value to the string variable affects the future output of rnd() in some way? That, again, would be very weird, but the only possible explanation of what I just witnessed that occured to me so far.