Browse Source

Allocate screenshot pixel array on heap.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
d9078e3f69
2 changed files with 3 additions and 1 deletions
  1. +1
    -0
      src/main.cpp
  2. +2
    -1
      src/window.cpp

+ 1
- 0
src/main.cpp View File

@@ -165,6 +165,7 @@ int main(int argc, char *argv[]) {
std::this_thread::sleep_for(std::chrono::seconds(2)); std::this_thread::sleep_for(std::chrono::seconds(2));
} }
else if (screenshot) { else if (screenshot) {
INFO("Taking screenshots of all modules at %gx zoom", screenshotZoom);
APP->window->screenshot(screenshotZoom); APP->window->screenshot(screenshotZoom);
} }
else { else {


+ 2
- 1
src/window.cpp View File

@@ -431,7 +431,7 @@ void Window::screenshot(float zoom) {
// Read pixels // Read pixels
int width, height; int width, height;
nvgImageSize(vg, fb->getImageHandle(), &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); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);


// Flip image vertically // Flip image vertically
@@ -447,6 +447,7 @@ void Window::screenshot(float zoom) {
stbi_write_png(filename.c_str(), width, height, 4, data, width * 4); stbi_write_png(filename.c_str(), width, height, 4, data, width * 4);


// Cleanup // Cleanup
delete[] data;
nvgluBindFramebuffer(NULL); nvgluBindFramebuffer(NULL);
delete fb; delete fb;
} }


Loading…
Cancel
Save