Solved a bug when resizing window