mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-03 03:30:06 +00:00
Android: Fix issues with input stream special members
Fixes bugs in AndroidInputStreamWrapper introduced in
0d2e34f34c
- Now that AndroidInputStreamWrapper is moveable, its destructor must be
able to handle the situation where stream is null
- The move assignment operators of AndroidInputStreamWrapper and
AndroidContentUriInputStream could previously end up calling
themselves recursively
This commit is contained in:
parent
faf6d9976a
commit
add3a5de0d
2 changed files with 24 additions and 7 deletions
|
|
@ -560,8 +560,8 @@ struct AndroidStreamHelpers
|
|||
class AndroidInputStreamWrapper final : public InputStream
|
||||
{
|
||||
public:
|
||||
explicit AndroidInputStreamWrapper (jobject streamIn)
|
||||
: stream (LocalRef<jobject> { streamIn })
|
||||
explicit AndroidInputStreamWrapper (LocalRef<jobject> streamIn)
|
||||
: stream (std::move (streamIn))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -577,7 +577,7 @@ public:
|
|||
|
||||
AndroidInputStreamWrapper& operator= (AndroidInputStreamWrapper&& other) noexcept
|
||||
{
|
||||
std::swap (*this, other);
|
||||
AndroidInputStreamWrapper { std::move (other) }.swap (*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -585,6 +585,9 @@ public:
|
|||
|
||||
~AndroidInputStreamWrapper() override
|
||||
{
|
||||
if (stream == nullptr)
|
||||
return;
|
||||
|
||||
getEnv()->CallVoidMethod (stream.get(), AndroidInputStream.close);
|
||||
jniCheckHasExceptionOccurredAndClear();
|
||||
}
|
||||
|
|
@ -647,14 +650,22 @@ private:
|
|||
return skipped == num;
|
||||
}
|
||||
|
||||
void swap (AndroidInputStreamWrapper& other) noexcept
|
||||
{
|
||||
std::swap (other.byteArray, byteArray);
|
||||
std::swap (other.stream, stream);
|
||||
std::swap (other.pos, pos);
|
||||
std::swap (other.exhausted, exhausted);
|
||||
}
|
||||
|
||||
CachedByteArray byteArray;
|
||||
GlobalRef stream;
|
||||
int64 pos = 0;
|
||||
bool exhausted = false;
|
||||
};
|
||||
|
||||
std::unique_ptr<InputStream> makeAndroidInputStreamWrapper (jobject stream);
|
||||
std::unique_ptr<InputStream> makeAndroidInputStreamWrapper (jobject stream)
|
||||
std::unique_ptr<InputStream> makeAndroidInputStreamWrapper (LocalRef<jobject> stream);
|
||||
std::unique_ptr<InputStream> makeAndroidInputStreamWrapper (LocalRef<jobject> stream)
|
||||
{
|
||||
return std::make_unique<AndroidInputStreamWrapper> (stream);
|
||||
}
|
||||
|
|
@ -672,7 +683,7 @@ struct AndroidContentUriInputStream final : public InputStream
|
|||
|
||||
AndroidContentUriInputStream& operator= (AndroidContentUriInputStream&& other) noexcept
|
||||
{
|
||||
std::swap (*this, other);
|
||||
AndroidContentUriInputStream { std::move (other) }.swap (*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -744,6 +755,12 @@ private:
|
|||
return getPosition() == oldPosition + num;
|
||||
}
|
||||
|
||||
void swap (AndroidContentUriInputStream& other) noexcept
|
||||
{
|
||||
std::swap (other.stream, stream);
|
||||
std::swap (other.uri, uri);
|
||||
}
|
||||
|
||||
AndroidInputStreamWrapper stream;
|
||||
GlobalRef uri;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ DECLARE_JNI_CLASS (AndroidAssetManager, "android/content/res/AssetManager")
|
|||
#undef JNI_CLASS_MEMBERS
|
||||
|
||||
// Defined in juce_core
|
||||
std::unique_ptr<InputStream> makeAndroidInputStreamWrapper (jobject stream);
|
||||
std::unique_ptr<InputStream> makeAndroidInputStreamWrapper (LocalRef<jobject> stream);
|
||||
|
||||
struct AndroidCachedTypeface
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue