From 0f485416beb6406e4181f15f7453fdeae2e0874b Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Wed, 8 Jan 2025 05:31:42 +0300 Subject: [PATCH] Fix crash bug when saving source files for nxt --- .../nxtOsekCGenerator/nxtOsekCGeneratorPlugin.cpp | 14 ++++++++------ .../nxtOsekCGenerator/nxtOsekCGeneratorPlugin.h | 2 -- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.cpp b/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.cpp index e408cc20b2..cfe58cb83e 100644 --- a/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.cpp +++ b/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.cpp @@ -34,7 +34,6 @@ NxtOsekCGeneratorPlugin::NxtOsekCGeneratorPlugin() , mFlashRobotAction(new QAction(this)) , mUploadProgramAction(new QAction(this)) , mNxtToolsPresent(false) - , mMasterGenerator(nullptr) , mCommunicator(utils::Singleton::instance()) { initActions(); @@ -179,21 +178,24 @@ void NxtOsekCGeneratorPlugin::onUploadingComplete(bool success) generatorBase::MasterGeneratorBase *NxtOsekCGeneratorPlugin::masterGenerator() { - mMasterGenerator = new NxtOsekCMasterGenerator(*mRepo + return new NxtOsekCMasterGenerator(*mRepo , *mMainWindowInterface->errorReporter() , *mParserErrorReporter , *mRobotModelManager , *mTextLanguage , mMainWindowInterface->activeDiagram() , generatorName()); - return mMasterGenerator; } void NxtOsekCGeneratorPlugin::regenerateExtraFiles(const QFileInfo &newFileInfo) { - mMasterGenerator->initialize(); - mMasterGenerator->setProjectDir(newFileInfo); - mMasterGenerator->generateOilAndMakeFiles(); + // Static cast is possible and correct, but dynamic will be more flexible. + if (auto nxtGenerator = dynamic_cast(masterGenerator())) { + QScopedPointer generator(nxtGenerator); + generator->initialize(); + generator->setProjectDir(newFileInfo); + generator->generateOilAndMakeFiles(); + } } void NxtOsekCGeneratorPlugin::flashRobot() diff --git a/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.h b/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.h index b8e56e61d2..de32d029ef 100644 --- a/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.h +++ b/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.h @@ -89,8 +89,6 @@ private slots: bool mNxtToolsPresent { false }; /// Flasher object QScopedPointer mFlashTool; - - NxtOsekCMasterGenerator *mMasterGenerator; const QSharedPointer mCommunicator; };