Fix GUI crash when loading a project via the Load dialog

StackCreator::fromFile/AStack::loadWeights now append "/prj/<name>"
themselves (the prj/<name>/ 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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016K8Gu7Qejd11JbdiHZqYAs
This commit is contained in:
2026-07-27 16:07:47 +02:00
co-authored by Claude Sonnet 5
parent 797339a02f
commit da830e947f
+6 -1
View File
@@ -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 <root>/prj/<name>/<name>.prj; StackCreator/AStack
// append "/prj/<name>" themselves, so recover <root> (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<DeepStack*>(pStack);
m_stack->loadWeights(m_dir);
m_rbmSelect->clear(dontSendNotification);