Browse Source

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.
pull/162/head
falkTX 4 years ago
parent
commit
cc720fe821
2 changed files with 15 additions and 2 deletions
  1. +3
    -2
      dgl/src/Window.cpp
  2. +12
    -0
      distrho/extra/String.hpp

+ 3
- 2
dgl/src/Window.cpp View File

@@ -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



+ 12
- 0
distrho/extra/String.hpp View File

@@ -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


Loading…
Cancel
Save