aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/Irrlicht/COSOperator.cpp33
-rw-r--r--source/Irrlicht/COSOperator.h11
2 files changed, 30 insertions, 14 deletions
diff --git a/source/Irrlicht/COSOperator.cpp b/source/Irrlicht/COSOperator.cpp
index 132232f..1c3baf9 100644
--- a/source/Irrlicht/COSOperator.cpp
+++ b/source/Irrlicht/COSOperator.cpp
@@ -30,7 +30,7 @@
#include "fast_atof.h"
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
-static bool sdl_supports_primary_selection = [] {
+static const bool sdl_supports_primary_selection = [] {
#if SDL_VERSION_ATLEAST(2, 25, 0)
SDL_version linked_version;
SDL_GetVersion(&linked_version);
@@ -62,6 +62,15 @@ COSOperator::COSOperator(const core::stringc& osVersion) : OperatingSystem(osVer
}
+COSOperator::~COSOperator()
+{
+#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
+ SDL_free(ClipboardSelectionText);
+ SDL_free(PrimarySelectionText);
+#endif
+}
+
+
//! returns the current operating system version as string.
const core::stringc& COSOperator::getOperatingSystemVersion() const
{
@@ -142,11 +151,9 @@ void COSOperator::copyToPrimarySelection(const c8 *text) const
const c8* COSOperator::getTextFromClipboard() const
{
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
- static char *text = nullptr;
- if (text)
- SDL_free(text);
- text = SDL_GetClipboardText();
- return text;
+ SDL_free(ClipboardSelectionText);
+ ClipboardSelectionText = SDL_GetClipboardText();
+ return ClipboardSelectionText;
#elif defined(_IRR_WINDOWS_API_)
if (!OpenClipboard(NULL))
@@ -195,19 +202,17 @@ const c8* COSOperator::getTextFromPrimarySelection() const
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
#if SDL_VERSION_ATLEAST(2, 25, 0)
if (sdl_supports_primary_selection) {
- static char *text = nullptr;
- if (text)
- SDL_free(text);
- text = SDL_GetPrimarySelectionText();
- return text;
+ SDL_free(PrimarySelectionText);
+ PrimarySelectionText = SDL_GetPrimarySelectionText();
+ return PrimarySelectionText;
}
#endif
return 0;
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
- if ( IrrDeviceLinux )
- return IrrDeviceLinux->getTextFromPrimarySelection();
- return 0;
+ if ( IrrDeviceLinux )
+ return IrrDeviceLinux->getTextFromPrimarySelection();
+ return 0;
#else
diff --git a/source/Irrlicht/COSOperator.h b/source/Irrlicht/COSOperator.h
index 6510579..941dacc 100644
--- a/source/Irrlicht/COSOperator.h
+++ b/source/Irrlicht/COSOperator.h
@@ -23,6 +23,11 @@ public:
#endif
COSOperator(const core::stringc& osversion);
+ ~COSOperator();
+
+ COSOperator(const COSOperator &) = delete;
+ COSOperator &operator=(const COSOperator &) = delete;
+
//! returns the current operation system version as string.
const core::stringc& getOperatingSystemVersion() const override;
@@ -56,6 +61,12 @@ private:
mutable core::stringc ClipboardBuf;
#endif
+#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
+ // These need to be freed with SDL_free
+ mutable char *ClipboardSelectionText = nullptr;
+ mutable char *PrimarySelectionText = nullptr;
+#endif
+
};
} // end namespace