Bug 504983 - KWin Scripting API - Crash when Assigning Window::desktops to Array of Strings instead of Array of KWin::VirtualDesktop*
Summary: KWin Scripting API - Crash when Assigning Window::desktops to Array of String...
Status: CONFIRMED
Alias: None
Product: kwin
Classification: Plasma
Component: general (other bugs)
Version First Reported In: 6.3.5
Platform: openSUSE Linux
: NOR crash
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords: drkonqi
Depends on:
Blocks:
 
Reported: 2025-05-29 20:51 UTC by stellarpower
Modified: 2025-05-30 18:40 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report: https://crash-reports.kde.org/organizations/kde/issues/189358/events/091aa226761447429e29bd02ea2863d8/


Attachments
New crash information added by DrKonqi (218.03 KB, text/plain)
2025-05-29 20:51 UTC, stellarpower
Details

Note You need to log in before you can comment on or make changes to this bug.
Description stellarpower 2025-05-29 20:51:10 UTC
Application: kwin_wayland (6.3.5)

ApplicationNotResponding [ANR]: false
Qt Version: 6.9.0
Frameworks Version: 6.13.0
Operating System: Linux 6.14.6-1.0.4.sr20250501-default x86_64
Windowing System: Wayland
Distribution: "openSUSE Tumbleweed-Slowroll"
DrKonqi: 6.3.5 [CoredumpBackend]

-- Information about the crash:
I have been working on a KWin script to combine the functionality of "Show in Activities" and "Show on Desktops" from the window actions menu into one menu, so that I can file a window away exactly where I want it in one click (plan to upload it, if anyone happens ot be interested).

Whilst developing this, I accidentally assigned to the list of desktops on which a window is active from an array of strings (with the desktop name), as we do for activities, instead of an array of pointers to the exposed KWin::VirtualDesktop instances.

MRE:

``Javascript

var activityUUID = /* ... */ "2a96ec5f-5da8-4cc8-b92f-eeebc91287a5";
var desktop      = workspace.desktops[0];
var desktopName  = desktop.name;



    workspace.activeWindow.activities = [activityUUID]
    //workspace.activeWindow.desktops   = [desktopName ] // Whoops
  workspace.activeWindow.desktops   = [desktop     ] // This is what we meant.

```

This causes a crash in KWin (not a terrible one, as all my applications survive it), rather than the expected behaviour of some kind of typecast error being logged to journalctl and having the compositor conitnue on its merry way.

I haven't looked at the source yet, but scanning the backtrace, it seems it gets reasonably far down with a null KWin::VirtualDesktop*, which to me would suggest a cast has failed but the result has not been checked somewhere before continuing.

I can also reproduce it putting anything inside the array, i.e.

``Javascript
workspace.activeWindow.desktops   = [8008135]
```

The crash can be reproduced every time.

-- Backtrace (Reduced):
#5  QArrayDataPointer<char16_t>::QArrayDataPointer (this=<optimized out>, other=...) at /usr/include/qt6/QtCore/qarraydatapointer.h:37
#6  QString::QString (this=<optimized out>, other=..., this=<optimized out>, other=<optimized out>) at /usr/include/qt6/QtCore/qstring.h:1339
#7  KWin::VirtualDesktop::id (this=0x0, this=<optimized out>) at /usr/src/debug/kwin-6.3.5/src/virtualdesktops.h:47
#8  KWin::Window::setDesktops (this=0x563ca0056190, desktops=...) at /usr/src/debug/kwin-6.3.5/src/window.cpp:734
#9  0x00007f7172a63ec8 in KWin::Window::qt_static_metacall (_o=<optimized out>, _c=<optimized out>, _id=<optimized out>, _a=<optimized out>) at /usr/src/debug/kwin-6.3.5/build/src/kwin_autogen/include/moc_window.cpp:931


Reported using DrKonqi
Comment 1 stellarpower 2025-05-29 20:51:11 UTC
Created attachment 181883 [details]
New crash information added by DrKonqi

DrKonqi auto-attaching complete backtrace.