From d9078e3f699af7d38b0e5c99d68ff1b0398b90e4 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 8 May 2019 20:36:07 -0400 Subject: [PATCH] Allocate screenshot pixel array on heap. --- src/main.cpp | 1 + src/window.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 46270cfa..f02e2e34 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -165,6 +165,7 @@ int main(int argc, char *argv[]) { std::this_thread::sleep_for(std::chrono::seconds(2)); } else if (screenshot) { + INFO("Taking screenshots of all modules at %gx zoom", screenshotZoom); APP->window->screenshot(screenshotZoom); } else { diff --git a/src/window.cpp b/src/window.cpp index 57bd5374..c215aaac 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -431,7 +431,7 @@ void Window::screenshot(float zoom) { // Read pixels int width, height; nvgImageSize(vg, fb->getImageHandle(), &width, &height); - uint8_t data[height * width * 4]; + uint8_t *data = new uint8_t[height * width * 4]; glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); // Flip image vertically @@ -447,6 +447,7 @@ void Window::screenshot(float zoom) { stbi_write_png(filename.c_str(), width, height, 4, data, width * 4); // Cleanup + delete[] data; nvgluBindFramebuffer(NULL); delete fb; }