From 68497a6c2c79c0db837a446190565834856ece24 Mon Sep 17 00:00:00 2001 From: Rene Zeldenthuis Date: Tue, 18 Oct 2022 09:46:36 +0200 Subject: [PATCH] Added checks for snapshot --- src/main.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a46af8c..7602d86 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -150,13 +150,19 @@ void handle_snapshot() } cam.run(); + if (cam.getSize() == 0 || cam.getfb() == nullptr) + { + web_server.send(404, "text/plain", "Unable to obtain framebuffer"); + return; + } + auto fb_len = cam.getSize(); - auto fb = (const char*)memcpy(new uint8_t[fb_len], cam.getfb(), fb_len); + auto fb = (const char *)memcpy(new uint8_t[fb_len], cam.getfb(), fb_len); web_server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); web_server.setContentLength(fb_len); web_server.send(200, "image/jpeg", ""); web_server.sendContent(fb, fb_len); - delete []fb; + delete[] fb; } void on_config_saved() @@ -208,7 +214,7 @@ void on_connected() log_v("on_connected"); // Turn LED off (has inverted logic GPIO33) digitalWrite(LED_BUILTIN, true); - // Start (OTA) Over The Air programming when connected + // Start (OTA) Over The Air programming when connected ArduinoOTA.begin(); // Start the RTSP Server start_rtsp_server();