fixed a bug on setting viewport

Fixed a bug on setting viewport that may cause a fatal error if the
required framebuffer size exceeds the allocated one.