From 36bb3c45312c54e7d7d49da7ebb27a831baf5cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Marsza=C5=82ek?= <1aam2am1@users.noreply.github.com> Date: Mon, 8 Feb 2016 18:09:59 +0100 Subject: [PATCH] Added pointer checks to Android's resource stream. This fixes issues #1056. --- src/SFML/System/Android/ResourceStream.cpp | 41 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/SFML/System/Android/ResourceStream.cpp b/src/SFML/System/Android/ResourceStream.cpp index fbc1ec4fa..93280aa67 100644 --- a/src/SFML/System/Android/ResourceStream.cpp +++ b/src/SFML/System/Android/ResourceStream.cpp @@ -49,35 +49,66 @@ m_file (NULL) //////////////////////////////////////////////////////////// ResourceStream::~ResourceStream() { - AAsset_close(m_file); + if (m_file) + { + AAsset_close(m_file); + } } //////////////////////////////////////////////////////////// Int64 ResourceStream::read(void *data, Int64 size) { - return AAsset_read(m_file, data, size); + if (m_file) + { + return AAsset_read(m_file, data, size); + } + else + { + return -1; + } } //////////////////////////////////////////////////////////// Int64 ResourceStream::seek(Int64 position) { - return AAsset_seek(m_file, position, SEEK_SET); + if (m_file) + { + return AAsset_seek(m_file, position, SEEK_SET); + } + else + { + return -1; + } } //////////////////////////////////////////////////////////// Int64 ResourceStream::tell() { - return getSize() - AAsset_getRemainingLength(m_file); + if (m_file) + { + return getSize() - AAsset_getRemainingLength(m_file); + } + else + { + return -1; + } } //////////////////////////////////////////////////////////// Int64 ResourceStream::getSize() { - return AAsset_getLength(m_file); + if (m_file) + { + return AAsset_getLength(m_file); + } + else + { + return -1; + } }