fix bug when resizing window