UWP Web-reddit slideshow
#projects #uwp
This is probably the first, and the last app I will ever
publish on
Micro$oft's absolutely garbage
proprietary UWP platform (but hey,
it's at least better than the apple one, as I'm not extorted by a
hostile company to even have the possibility of users being able to
use my apps).
Following on from my prior project of implementing a reddit slideshow in the web, the natural place to go from here was to try and do this on a native platform.
At this point in my life, I had not yet learnt of The One True Path of Free Open Source Software, nor had I developed my current revulsion to Micro$oft (in fact, I was even willing to work with them), so I decided to try and build this project using UWP.
Company-related issues aside, I recall the platform as being suprisingly nice to develop for, and it was quite easy to actually set up the app.
This project also has a rather fun debugging story associated with it, which I've quoted below from the project page:
As I was developing the application on a local platform, I wanted to also encorperate buffering features (yes I know I could have done this on the web one as well, but developing locally I had no excuses). Initially I tried to implement it by encapsulating the storage and retrieval of the image into the class. When retrieve content was called the class would request an image from it's url and store it locally. However this ran into memory issues as I never removed the images.
Then as a quick fix, I made the application delete the 2nd previous image if the memory use was too high(>500mb) - this was a foolish decision as the user was also provided the ability to jump to random positions throughout the list of images. This meant that if the user jumped around they could end up crashing the application from a memory excess. I also converted my manual stream/byte based image retrieval functions to use the Image class supplied by the framework, as this would encapsulate that functionality, and also according to the MSDN would allow for image reuse - as in if the same image is fetched from multiple locations, only one copy would be required.
After this, I spent some time thinking through the image retrieval process (making sure to 'commit' this to memory as Image prefetching had been a subject I have thought about in a project previously) and came up with a better method. The Image list keeps track of the direction the user has just taken and uses it to prefetch the next image in that direction - the list also keeps a reference to the image it has prefetched. If the user jumps, their direction is set to none, and the previoiusly prefetched image is deleted. Then once the user starts moving again and a direction has been established, I restart the prefetching.
Even after this laborious task, I still kept on running into crashes. After spending some while in the debugger, I isolated the issue down to a memory spike at generation. What was interesting about this spike was that it didn't occur in the request json from reddit loop, but was also proporitional to the number of subreddits being requested. After about 2 hours of headscratching I finally noticed the issue - oh and what a frustrating issue it was - it turns out I had placed a listener on the Image list too early, which meant that as I populated the list, the callback would get fired like crazy, each time opening a stack frame again and again. This would cause the memory to exceed the limit and cause the crash. After a simple text movement, the application would work perfectly again.
You can find the project here: UWP-reddit-slideshow