DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit cc720fe821de52c5691c59b8fe21fd0793155a91
parent a7706f24a3f76c56a44eafe16ccd0618c07ce831
Author: falkTX <falktx@falktx.com>
Date:   Sat, 20 Jul 2019 12:38:13 +0200

win32: clear file dialog string before triggering callback
Things would go weird if a plugin opens a new file dialog in the
file callback, prevent this by clearing the string before the callback.

Diffstat:
Mdgl/src/Window.cpp | 5+++--
Mdistrho/extra/String.hpp | 12++++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp @@ -780,8 +780,9 @@ struct Window::PrivateData { #if defined(DISTRHO_OS_WINDOWS) && !defined(DGL_FILE_BROWSER_DISABLED) if (fSelectedFile.isNotEmpty()) { - fView->fileSelectedFunc(fView, fSelectedFile.buffer()); - fSelectedFile.clear(); + char* const buffer = fSelectedFile.getAndReleaseBuffer(); + fView->fileSelectedFunc(fView, buffer); + std::free(buffer); } #endif diff --git a/distrho/extra/String.hpp b/distrho/extra/String.hpp @@ -568,6 +568,18 @@ public: return fBuffer; } + /* + * Get and release the string buffer, while also clearing this string. + * Result must be freed. + */ + char* getAndReleaseBuffer() noexcept + { + char* const ret = fBuffer; + fBuffer = _null(); + fBufferLen = 0; + return ret; + } + // ------------------------------------------------------------------- // base64 stuff, based on http://www.adp-gmbh.ch/cpp/common/base64.html // Copyright (C) 2004-2008 René Nyffenegger