From d1a9cecf593bc81799321b0e1a8871d7f5547a44 Mon Sep 17 00:00:00 2001 From: Kwangsub Kim Date: Thu, 20 Oct 2022 17:14:09 +0200 Subject: [PATCH] McuSupport: Fix crash when there is no proper desktop toolchain Desktop toolchain is picked up from the registered toolchains in Qt Creator, but it can be failed, for instance when there is no toolchain for MinGW, and it causes crash for now. An error handling is added to avoid it and inform to a user. Task-number: QTCREATORBUG-28296 Change-Id: Ie16cd6c75df9be510bb49b765ad61ddf189a41db Reviewed-by: Christian Stenger --- src/plugins/mcusupport/mcukitmanager.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/plugins/mcusupport/mcukitmanager.cpp b/src/plugins/mcusupport/mcukitmanager.cpp index ce846ffc708..e400eefa7b8 100644 --- a/src/plugins/mcusupport/mcukitmanager.cpp +++ b/src/plugins/mcusupport/mcukitmanager.cpp @@ -10,6 +10,7 @@ #include "mcusupportconstants.h" #include "mcusupportplugin.h" #include "mcusupportsdk.h" +#include "mcusupporttr.h" #include "mcutarget.h" #include @@ -247,10 +248,19 @@ public: auto cxxToolchain = toolchainPackage->toolChain( ProjectExplorer::Constants::CXX_LANGUAGE_ID); - configMap.insert("CMAKE_CXX_COMPILER", - cxxToolchain->compilerCommand().toString().toLatin1()); - configMap.insert("CMAKE_C_COMPILER", - cToolchain->compilerCommand().toString().toLatin1()); + if (cToolchain && cxxToolchain) { + configMap.insert("CMAKE_CXX_COMPILER", + cxxToolchain->compilerCommand().toString().toLatin1()); + configMap.insert("CMAKE_C_COMPILER", + cToolchain->compilerCommand().toString().toLatin1()); + } else { + printMessage(Tr::tr("Warning for target %1: invalid toolchain path (%2). " + "Update the toolchain in Edit > Preferences > Kits.") + .arg(generateKitNameFromTarget(mcuTarget), + toolchainPackage->path().toUserOutput()), + true); + } + } else { const FilePath cMakeToolchainFile = mcuTarget->toolChainFilePackage()->path();