[education/rkward] /: Fix crash on script errors in plugins, and somewhat better location reporting

Thomas Friedrichsmeier null at kde.org
Wed May 7 14:21:36 BST 2025


Git commit 49a6957056c3370178ef0951d7dea0f6981e6d82 by Thomas Friedrichsmeier.
Committed on 07/05/2025 at 13:21.
Pushed by tfry into branch 'master'.

Fix crash on script errors in plugins, and somewhat better location reporting

M  +1    -0    ChangeLog
M  +1    -5    rkward/misc/rkaccordiontable.cpp
M  +2    -4    rkward/plugin/rkstandardcomponent.cpp
M  +5    -6    rkward/scriptbackends/rkcomponentscripting.cpp
M  +1    -1    rkward/scriptbackends/rkcomponentscripting.h

https://invent.kde.org/education/rkward/-/commit/49a6957056c3370178ef0951d7dea0f6981e6d82

diff --git a/ChangeLog b/ChangeLog
index e1517ebbb..3d25dc454 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
 --- Version 0.8.2 - UNRELEASED
+- Fixed: Crash on script errors in plugins
 - Fixed: Printing of captured R messages/warnings in plugins was broken
 - Internal: Code cleanups
 - Internal: Remove dependency on Qt5-compatibility library
diff --git a/rkward/misc/rkaccordiontable.cpp b/rkward/misc/rkaccordiontable.cpp
index bdb25e10a..5069a636e 100644
--- a/rkward/misc/rkaccordiontable.cpp
+++ b/rkward/misc/rkaccordiontable.cpp
@@ -263,7 +263,7 @@ RKAccordionTable::RKAccordionTable(QWidget *parent) : QTreeView(parent) {
 	setItemsExpandable(false);      // custom handling
 	setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
 
-	pmodel = new RKAccordionDummyModel(nullptr);
+	pmodel = new RKAccordionDummyModel(this);
 	RKAccordionDelegate *delegate = new RKAccordionDelegate(this);
 	delegate->pmodel = pmodel;
 	setItemDelegateForColumn(0, delegate);
@@ -275,10 +275,6 @@ RKAccordionTable::RKAccordionTable(QWidget *parent) : QTreeView(parent) {
 RKAccordionTable::~RKAccordionTable() {
 	RK_TRACE(MISC);
 
-	// Qt 4.8.6: The model must _not_ be a child of this view, and must _not_ be deleted along with it, or else there will be a crash
-	// on destruction _if_ (and only if) there are any trailing dummy rows. (Inside QAbstractItemModelPrivate::removePersistentIndexData())
-	// No, I do not understand this, yes, this is worrysome, but no idea, what could be the actual cause.
-	pmodel->deleteLater();
 	delete editor_widget_container;
 }
 
diff --git a/rkward/plugin/rkstandardcomponent.cpp b/rkward/plugin/rkstandardcomponent.cpp
index d5e488733..72e8e54d9 100644
--- a/rkward/plugin/rkstandardcomponent.cpp
+++ b/rkward/plugin/rkstandardcomponent.cpp
@@ -172,10 +172,8 @@ void RKStandardComponent::kill() {
 
 	if (killed) return;
 	killed = true;
-
-	hide();
-	removeFromParent();
-	deleteLater();
+	if (parentComponent()) topmostStandardComponent()->kill();
+	if (gui) gui->deleteLater();
 }
 
 RKComponentScriptingProxy *RKStandardComponent::scriptingProxy() {
diff --git a/rkward/scriptbackends/rkcomponentscripting.cpp b/rkward/scriptbackends/rkcomponentscripting.cpp
index 9bed5fa72..8911c3c60 100644
--- a/rkward/scriptbackends/rkcomponentscripting.cpp
+++ b/rkward/scriptbackends/rkcomponentscripting.cpp
@@ -9,7 +9,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 
 #include <KLocalizedString>
 #include <QDir>
-#include <kmessagebox.h>
+#include <KMessageBox>
 
 #include "../core/robjectlist.h"
 #include "../misc/rkcommonfunctions.h"
@@ -81,16 +81,15 @@ void RKComponentScriptingProxy::include(const QString &filename) {
 		return;
 	}
 
-	evaluate(QString::fromUtf8(file.readAll()));
-	handleScriptError(_filename);
+	evaluate(QString::fromUtf8(file.readAll()), _filename);
 }
 
-void RKComponentScriptingProxy::evaluate(const QString &code) {
+void RKComponentScriptingProxy::evaluate(const QString &code, const QString &filename) {
 	RK_TRACE(PHP);
 
-	QJSValue result = engine.evaluate(code, _scriptfile);
+	QJSValue result = engine.evaluate(code, filename.isNull() ? _scriptfile : filename);
 
-	handleScriptError(result);
+	handleScriptError(result, filename);
 }
 
 void RKComponentScriptingProxy::addChangeCommand(const QString &changed_id, const QString &command) {
diff --git a/rkward/scriptbackends/rkcomponentscripting.h b/rkward/scriptbackends/rkcomponentscripting.h
index aa0d9424a..735b90c5e 100644
--- a/rkward/scriptbackends/rkcomponentscripting.h
+++ b/rkward/scriptbackends/rkcomponentscripting.h
@@ -67,7 +67,7 @@ class RKComponentScriptingProxy : public QObject {
 	};
 	QList<OutstandingCommand> outstanding_commands;
 	QString _scriptfile;
-	void evaluate(const QString &code);
+	void evaluate(const QString &code, const QString &filename=QString());
 
 	void handleChange(RKComponentBase *changed);
 	QHash<RKComponentBase *, QString> component_commands;



More information about the rkward-tracker mailing list