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));
}
else if (screenshot) {
INFO("Taking screenshots of all modules at %gx zoom", screenshotZoom);
APP->window->screenshot(screenshotZoom);
}
else {


+ 2
- 1
src/window.cpp View File

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


Loading…
Cancel
Save