From fb1b30b72886b7fb932dda93d42fb0b787e9b478 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 4 Jun 2021 12:31:15 +1000 Subject: [PATCH] [host] app: calculate and report the required IVSHMEM size One of the most common issues reported in the support channels is the IVSHMEM size being too small. This change adds a calculation to determine an optimal size and uses the new `os_showMessage` platform method to display a message box to the user with the error. --- host/include/interface/platform.h | 1 + host/platform/Windows/src/platform.c | 5 +++++ host/src/app.c | 13 ++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/host/include/interface/platform.h b/host/include/interface/platform.h index c9b1beef..ddd57778 100644 --- a/host/include/interface/platform.h +++ b/host/include/interface/platform.h @@ -40,5 +40,6 @@ void app_quit(); // these must be implemented for each OS const char * os_getExecutable(); const char * os_getDataPath(); +void os_showMessage(const char * caption, const char * msg); bool os_blockScreensaver(); diff --git a/host/platform/Windows/src/platform.c b/host/platform/Windows/src/platform.c index 2e0c0a2d..3931cd24 100644 --- a/host/platform/Windows/src/platform.c +++ b/host/platform/Windows/src/platform.c @@ -537,3 +537,8 @@ bool os_blockScreensaver() } return lastResult; } + +void os_showMessage(const char * caption, const char * msg) +{ + MessageBoxA(NULL, msg, caption, MB_OK | MB_ICONINFORMATION); +} diff --git a/host/src/app.c b/host/src/app.c index 7f092117..dea3a158 100644 --- a/host/src/app.c +++ b/host/src/app.c @@ -30,6 +30,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "common/ivshmem.h" #include "common/sysinfo.h" #include "common/time.h" +#include "common/stringutils.h" #include @@ -38,6 +39,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include #include +#include #define CONFIG_FILE "looking-glass-host.ini" #define POINTER_SHAPE_BUFFERS 3 @@ -295,7 +297,16 @@ static bool captureStart(void) const unsigned int maxFrameSize = app.iface->getMaxFrameSize(); if (maxFrameSize > app.maxFrameSize) { - DEBUG_ERROR("Maximum frame size of %d bytes excceds maximum space available", maxFrameSize); + DEBUG_ERROR("Maximum frame size of %d bytes exceeds maximum space available", maxFrameSize); + + const float needed = ((maxFrameSize * 2) / 1048576.0f) + 10.0f; + const int size = (int)powf(2.0f, ceilf(logf(needed) / logf(2.0f))); + + char * msg; + alloc_sprintf(&msg, "IVSHMEM size too small, increase to %d MiB", size); + os_showMessage("Looking Glass Error", msg); + free(msg); + return false; } DEBUG_INFO("Capture Size : %u MiB (%u)", maxFrameSize / 1048576, maxFrameSize);