You can make it "safe" by changing WritePixelFast (all 16 of them) to wpf and adding this function
but this slows it down by about three times. Note that GAME_WIDTH and GAME_HEIGHT are global variables or constants.
You could also make the buffer that is locked into a variable that is passed in for greater flexibility.
Function wpf(x,y,c) ;safe WritePixelFast If x<0 Or x>=GAME_WIDTH Then Return 0 If y<0 Or y>=GAME_HEIGHT Then Return 0 WritePixelFast(x,y,c) End Function
but this slows it down by about three times. Note that GAME_WIDTH and GAME_HEIGHT are global variables or constants.
You could also make the buffer that is locked into a variable that is passed in for greater flexibility.