[education/rkward] rkward/rbackend/rkwarddevice: Hotfix for another crash in device destruction

Thomas Friedrichsmeier null at kde.org
Sun Aug 24 16:08:55 BST 2025


Git commit d670532889ea4efc96c4375b3a84b53c915740e8 by Thomas Friedrichsmeier.
Committed on 24/08/2025 at 15:06.
Pushed by tfry into branch 'master'.

Hotfix for another crash in device destruction

M  +2    -1    rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
M  +1    -0    rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp

https://invent.kde.org/education/rkward/-/commit/d670532889ea4efc96c4375b3a84b53c915740e8

diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
index 30a3130c9..1be8a73e5 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
@@ -198,6 +198,7 @@ void RKGraphicsDevice::checkSize() {
 	if (!view) return;
 	if (view->size() != area.size()) {
 		if (view->size().isEmpty()) return;
+#warning FIXME Sometimes called after closeDevice (key no longer present).
 		RInterface::issueCommand(
 		    new RCommand(u"rkward:::RK.resize("_s + QString::number(devices.key(this) + 1) + u',' + QString::number(id) + u')', RCommand::PriorityCommand));
 	}
@@ -222,7 +223,7 @@ void RKGraphicsDevice::closeDevice(int devnum) {
 	RK_ASSERT(devices.contains(devnum));
 	auto dev = devices.take(devnum);
 	dev->deleteLater();
-	Q_EMIT dev->deviceClosed(devnum);
+	Q_EMIT dev->deviceClosed(devnum+1);  // TODO: review the +1s used everywhere
 }
 
 void RKGraphicsDevice::clear(const QBrush &brush) {
diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
index dbd148b92..d0c111c79 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
@@ -289,6 +289,7 @@ SEXP RKD_AdjustSize(SEXP _devnum, SEXP _id) {
 	RK_TRACE(GRAPHICS_DEVICE);
 	int devnum = RFn::Rf_asInteger(_devnum);
 	quint32 id = RFn::Rf_asInteger(_id);
+	if (devnum < 1) RFn::Rf_error("RKD_AdjustSize called on null device");
 	pGEDevDesc gdev = RFn::GEgetDevice(devnum);
 	if (!gdev) RFn::Rf_error("No such device %d", devnum);
 	pDevDesc dev = gdev->dev;



More information about the rkward-tracker mailing list