From 61fac7791e2c17be946ae54d2f485f02732ac40a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ladislav=20L=C3=A1ska?= <krakonos@krakonos.org>
Date: Thu, 26 Sep 2024 22:53:56 +0200
Subject: [PATCH] Fixed a crash on download when no server is loaded from
 config.

Default osm server is loaded with no credentials.
---
 src/Preferences/MerkaartorPreferences.cpp | 5 +++++
 src/Utils/OsmServer.h                     | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/src/Preferences/MerkaartorPreferences.cpp b/src/Preferences/MerkaartorPreferences.cpp
index 25c7a16c..0e35b165 100644
--- a/src/Preferences/MerkaartorPreferences.cpp
+++ b/src/Preferences/MerkaartorPreferences.cpp
@@ -630,6 +630,11 @@ void MerkaartorPreferences::initialize()
 
     }
 
+    if (theOsmServers.size() == 0) {
+        theOsmServers.append(defaultOsmServerInfo);
+        qDebug(lc_MerkaartorPreferences) << "No OSM servers found, adding default server.";
+    }
+
     //Ensure we have a CacheDir value in QSettings
     if (!g_Merk_Ignore_Preferences)
         Sets->setValue("backgroundImage/CacheDir", Sets->value("backgroundImage/CacheDir", HOMEDIR + "/BackgroundCache"));
diff --git a/src/Utils/OsmServer.h b/src/Utils/OsmServer.h
index 1b23ff72..302d0421 100644
--- a/src/Utils/OsmServer.h
+++ b/src/Utils/OsmServer.h
@@ -46,6 +46,8 @@ struct OsmServerInfo
     int CfgVersion = 1;
 };
 
+OsmServerInfo const defaultOsmServerInfo = OsmServerInfo{true, OsmServerInfo::AuthType::OAuth2Redirect, "https://www.openstreetmap.org/", "", ""};
+
 class IOsmServerImpl : public QObject {
     Q_OBJECT
 
