From fd95b49270dbfec647aaf4951e5ccc7d2bb4cfed Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 19 Oct 2023 08:33:37 +0800 Subject: [PATCH] - fix: Correctly handle project templates that have wrong unit counts. --- NEWS.md | 4 ++-- RedPandaIDE/project.cpp | 2 ++ RedPandaIDE/projecttemplate.cpp | 1 + RedPandaIDE/resources/templates/empty.template | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 30ff5056..6813960f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,12 +12,12 @@ Red Panda C++ Version 2.25 - Change: Empty project template won't auto create main.c/main.cpp - enhancement: When creating project, warn user if the project folder is not empty. - fix: Press '>' after '-' don't show completion suggestion info. - - fix: Icon position not correct under hiPDI devices. - - change: Add Mesa3D for windows opengl driver to the integrated mingw-gcc for windows 32 version. + - fix: Icon position not correct under hiDPI devices and zoom factor >= 200%. - enhancement: After compiler settings changed, run/debug current file will auto recompile. - ehhancement: Show selected char counts in status bar. - enhancement: Differentiate /* and /** when calculate auto indents. - fix: crash when using ibus as the input method. + - fix: Correctly handle project templates that have wrong unit counts. Red Panda C++ Version 2.24 diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index cdf273fd..4c2b0464 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -970,6 +970,8 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate, b for (int i=0;iunitCount();i++) { // Pick file contents PTemplateUnit templateUnit = aTemplate->unit(i); + if (!templateUnit) + continue; if (!templateUnit->Source.isEmpty()) { QString target = templateUnit->Source; PProjectUnit unit; diff --git a/RedPandaIDE/projecttemplate.cpp b/RedPandaIDE/projecttemplate.cpp index 4b9bdb3a..3dd3f95e 100644 --- a/RedPandaIDE/projecttemplate.cpp +++ b/RedPandaIDE/projecttemplate.cpp @@ -37,6 +37,7 @@ PTemplateUnit ProjectTemplate::unit(int index) if (!mIni || mVersion<=0) return PTemplateUnit(); QString section = QString("Unit%1").arg(index); + if (mIni->GetSectionSize(toByteArray(section))<0) return PTemplateUnit(); PTemplateUnit unit = std::make_shared(); QString lang = pSettings->environment().language(); if (!lang.isEmpty()) { diff --git a/RedPandaIDE/resources/templates/empty.template b/RedPandaIDE/resources/templates/empty.template index 1029a68c..bbbf9d78 100644 --- a/RedPandaIDE/resources/templates/empty.template +++ b/RedPandaIDE/resources/templates/empty.template @@ -9,5 +9,5 @@ Category=Basic Category[zh_CN]=基础 [Project] -UnitCount=1 +UnitCount=0 Type=1