From da830e947fa328273d71266c94b2f5186459c4fd Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 27 Jul 2026 16:07:47 +0200 Subject: [PATCH] Fix GUI crash when loading a project via the Load dialog StackCreator::fromFile/AStack::loadWeights now append "/prj/" themselves (the prj// restructure), expecting dir to be the repo root -- which poet.cpp and the GUI's startup auto-load already pass. But the Load button's file chooser used the picked file's own parent folder (e.g. prj/prims/) as dir, so after the refactor it looked for prj/prims/prj/prims/prims.prj, threw an uncaught Json::RuntimeError, and took the whole process down. Reproduced by actually launching the GUI, clicking Load, and picking prj/prims/prims.prj -- confirmed the crash, then confirmed the fix with the identical click sequence (project loads, weight visualizations render correctly). Fix: recover the repo root by going up three levels from the picked file (file -> its project folder -> "prj" folder -> root) and store it in m_dir, instead of using the file's immediate parent. This also fixes a separate dormant bug: m_dir was never updated after loading a different project through this dialog, so Save/Save Training would have silently written to whatever m_dir happened to be (always "."), regardless of which project was actually loaded. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_016K8Gu7Qejd11JbdiHZqYAs --- source/MainComponent.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/MainComponent.cpp b/source/MainComponent.cpp index 3946e76..199b092 100644 --- a/source/MainComponent.cpp +++ b/source/MainComponent.cpp @@ -585,7 +585,12 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) { m_file = fc->getResult(); projectNameLabel->setText(m_file.getFileNameWithoutExtension(), NotificationType::dontSendNotification); - AStack *pStack = StackCreator::fromFile(m_file.getParentDirectory().getFullPathName().toStdString(), std::string(projectNameLabel->getText().getCharPointer()), this); + // Projects live at /prj//.prj; StackCreator/AStack + // append "/prj/" themselves, so recover (three levels + // up: file -> its project folder -> "prj" folder -> root) rather + // than passing the file's own parent folder as dir. + m_dir = m_file.getParentDirectory().getParentDirectory().getParentDirectory().getFullPathName().toStdString(); + AStack *pStack = StackCreator::fromFile(m_dir, std::string(projectNameLabel->getText().getCharPointer()), this); m_stack = reinterpret_cast(pStack); m_stack->loadWeights(m_dir); m_rbmSelect->clear(dontSendNotification);