fixed critical error in the render loop

The render loop in the sprite manager was receiving an "array out of
bounds" error. Corrected the size checks and added a null safety check.