From f7eba799075652a546ac1d32dd1e573e0a32b3dc Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 17 Apr 2021 17:58:48 +0200 Subject: [PATCH] Fixed memory leaks --- CMakeSettings.json | 13 +++++++++++++ src/main.cpp | 13 ++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CMakeSettings.json b/CMakeSettings.json index 0426906..7a9749f 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -11,6 +11,19 @@ "buildCommandArgs": "", "ctestCommandArgs": "", "cmakeToolchain": "C:/Users/Robert/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake" + }, + { + "name": "x64-Release", + "generator": "Ninja", + "configurationType": "RelWithDebInfo", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "cmakeToolchain": "C:/Users/Robert/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake", + "inheritEnvironments": [ "msvc_x64_x64" ], + "variables": [] } ] } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 24d08f0..1b085d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,12 +30,18 @@ typedef struct sHighway int main(int argc, char** argv) { + SDL_Init(SDL_INIT_VIDEO); // Load map data and calculate window size + SDL_DisplayMode DM; + SDL_GetCurrentDisplayMode(0, &DM); + + std::cout << "Loading and parsing OSM XML file. This might take a bit..." << std::flush; osmp::Object* obj = new osmp::Object("leipzig.osm"); + std::cout << "Done!" << std::endl; osmp::Bounds bounds = obj->bounds; float aspectRatio = (float)(bounds.maxlon - bounds.minlon) / (float)(bounds.maxlat - bounds.minlat); - int windowWidth = 2000; - int windowHeight = windowWidth / aspectRatio; + int windowHeight = DM.h - 100; + int windowWidth = windowHeight * aspectRatio; // Fetch all the ways std::vector> ways = obj->GetWays(); @@ -132,9 +138,6 @@ int main(int argc, char** argv) ways.clear(); delete obj; - // Initiaize graphics API - SDL_Init(SDL_INIT_VIDEO); - // Create Window + Renderer SDL_Window* window = SDL_CreateWindow("MapViewer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, windowWidth, windowHeight, SDL_WINDOW_SHOWN); if (window == nullptr)