Also, you shouldn't have to change this canvas.resize() call. The rect before was exactly fitting to the size of the bug.