Try moving setup of the input frame surface outside of the loop.