Summary Files Commits Branches @commit @diff @stats
path: root / src / LEDVideoWall.cpp
diff options
context:
space:
mode:
Commit92630c6d0a1928e6f112013a45b9b681d55c1d63 (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-07-23 14:36:53 +0300
Committer
 Syndamia <kamen@syndamia.com>
2025-07-23 14:36:53 +0300
Files29de5b32bbd3424ffaec04672d028c84a1c6c9dc /src/LEDVideoWall.cpp
screen-generator-nemetschek-92630c6d0a1928e6f112013a45b9b681d55c1d63.tar
screen-generator-nemetschek-92630c6d0a1928e6f112013a45b9b681d55c1d63.tar.gz
screen-generator-nemetschek-92630c6d0a1928e6f112013a45b9b681d55c1d63.zip
Parentd71c054e221013f5d5f24648ded514b475aed3df (diff)
feat: Check for invalid values in widths and heights
1 files changed, 45 insertions, 19 deletions
-rw-r--r--src/LEDVideoWall.cpp64
diff --git a/src/LEDVideoWall.cpp b/src/LEDVideoWall.cpp
index 45f66ba..f4f4e16 100644
--- a/src/LEDVideoWall.cpp
+++ b/src/LEDVideoWall.cpp
@@ -38,12 +38,20 @@ enum class LEDVideoWallType {
LEDVideoWall* LEDVideoWall::fromCommandLine() {
mm ipanel_width = 0, ipanel_height = 0;
- cli::scanTwoValues(
- "%dx%d",
- ipanel_width,
- ipanel_height,
- "Enter panel size (in the format 'WIDTHxHEIGHT'): ",
- "Invalid size, try again!");
+ do {
+ cli::scanTwoValues(
+ "%dx%d",
+ ipanel_width,
+ ipanel_height,
+ "Enter panel size (in the format 'WIDTHxHEIGHT'): ",
+ "Invalid size, try again!");
+
+ if (ipanel_width == 0 || ipanel_height == 0) {
+ std::cerr << "The panel width or height cannot be zero!" << std::endl;
+ continue;
+ }
+ break;
+ } while (true);
unsigned int itype = 2;
cli::readUserInputMax(
@@ -56,24 +64,42 @@ LEDVideoWall* LEDVideoWall::fromCommandLine() {
switch (type) {
case LEDVideoWallType::Freeform: {
mm iwall_max_width = 0, iwall_max_height = 0;
- cli::scanTwoValues(
- "%dx%d",
- iwall_max_width,
- iwall_max_height,
- "Enter singe wall size (in the format 'WIDTHxHEIGHT'): ",
- "Invalid size, try again!");
+ do {
+ cli::scanTwoValues(
+ "%dx%d",
+ iwall_max_width,
+ iwall_max_height,
+ "Enter singe wall size (in the format 'WIDTHxHEIGHT'): ",
+ "Invalid size, try again!");
+
+ if (iwall_max_width == 0 || iwall_max_height == 0) {
+ std::cerr << "The wall width or height cannot be zero!" << std::endl;
+ continue;
+ }
+ if (iwall_max_width < panel_width || iwall_max_height < panel_height) {
+ std::cerr << "The wall cannot be smaller than the panel!" << std::endl;
+ continue;
+ }
+ } while (true);
return LEDVideoWall::Freeform(ipanel_width, ipanel_height, iwall_max_width, iwall_max_height);
};
case LEDVideoWallType::Aspect: {
- mm i_width = 0, i_height = 0;
- cli::scanTwoValues(
- "%d:%d",
- i_width,
- i_height,
- "Enter aspect ratio (in the format 'width:height'): ",
- "Invalid input, try again!");
+ mm iaspect_width = 0, iaspect_height = 0;
+ do {
+ cli::scanTwoValues(
+ "%d:%d",
+ iaspect_width,
+ iaspect_height,
+ "Enter aspect ratio (in the format 'WIDTH:HEIGHT'): ",
+ "Invalid input, try again!");
+
+ if (iaspect_width == 0 || iaspect_height == 0) {
+ std::cerr << "The aspect ratio width or height cannot be zero!" << std::endl;
+ continue;
+ }
+ } while (true);
return LEDVideoWall::Aspect(ipanel_width, ipanel_height, i_width, i_height);
};