Fix crash when tapping left/right button very fast.

How to reproduce the crash:

* Load gallery with some images
* Go forward a few images
* Tap the back button very fast many times
* Hit it more times than you have images on the left

If you're fast enough, it should crash. Same situation happens when you go forward very fast till the end.