Skip to content

Commit

Permalink
Fix crash when generating screenshots (F9 key)
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Aug 28, 2023
1 parent 1c6cc08 commit 08763a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/CardinalUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void Engine_setAboutToClose(Engine*);
void Engine_setRemoteDetails(Engine*, remoteUtils::RemoteDetails*);
}
namespace window {
void WindowSetPluginUI(Window* window, DISTRHO_NAMESPACE::UI* ui);
void WindowSetPluginUI(Window* window, CardinalBaseUI* ui);
void WindowSetMods(Window* window, int mods);
void WindowSetInternalSize(rack::window::Window* window, math::Vec size);
}
Expand Down
13 changes: 8 additions & 5 deletions src/override/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ enum ScreenshotStep {
struct Window::Internal {
std::string lastWindowTitle;

DISTRHO_NAMESPACE::UI* ui = nullptr;
CardinalBaseUI* ui = nullptr;
DGL_NAMESPACE::NanoTopLevelWidget* tlw = nullptr;
DISTRHO_NAMESPACE::WindowParameters params;
DISTRHO_NAMESPACE::WindowParametersCallback* callback = nullptr;
Expand Down Expand Up @@ -370,7 +370,7 @@ void WindowSetPluginRemote(Window* const window, NanoTopLevelWidget* const tlw)
}
}

void WindowSetPluginUI(Window* const window, DISTRHO_NAMESPACE::UI* const ui)
void WindowSetPluginUI(Window* const window, CardinalBaseUI* const ui)
{
// if nanovg context failed, init only bare minimum
if (window->vg == nullptr)
Expand Down Expand Up @@ -598,7 +598,8 @@ static void Window__writeImagePNG(void* context, void* data, int size) {
CardinalBaseUI* const ui = static_cast<CardinalBaseUI*>(context);
if (char* const screenshot = String::asBase64(data, size).getAndReleaseBuffer()) {
ui->setState("screenshot", screenshot);
remoteUtils::sendScreenshotToRemote(ui->remoteDetails, screenshot);
if (ui->remoteDetails != nullptr)
remoteUtils::sendScreenshotToRemote(ui->remoteDetails, screenshot);
std::free(screenshot);
}
}
Expand Down Expand Up @@ -731,10 +732,10 @@ void Window::step() {
if (internal->generateScreenshotStep == kScreenshotStepSaving)
{
// Write pixels to PNG
const int stride = winWidth * depth;
uint8_t* const pixelsWithOffset = pixels + (stride * y);
Window__flipBitmap(pixels, winWidth, winHeight, depth);
winHeight -= y;
const int stride = winWidth * depth;
uint8_t* const pixelsWithOffset = pixels + (stride * y);
#ifdef STBI_WRITE_NO_STDIO
Window__downscaleBitmap(pixelsWithOffset, winWidth, winHeight);
stbi_write_png_to_func(Window__writeImagePNG, internal->ui,
Expand All @@ -744,8 +745,10 @@ void Window::step() {
#endif

internal->generateScreenshotStep = kScreenshotStepNone;
#ifdef CARDINAL_TRANSPARENT_SCREENSHOTS
APP->scene->menuBar->show();
APP->scene->rack->children.front()->show();
#endif
}

delete[] pixels;
Expand Down

0 comments on commit 08763a2

Please sign in to comment.