fix error when canvas is not visible