add safeguards to draw_*_pixel() to prevent memory corruption