pencil2d / pencil

Pencil2D is an easy, intuitive tool to make 2D hand-drawn animations. Pencil2D is open source and cross-platform.
http://pencil2d.org
GNU General Public License v2.0
1.45k stars 272 forks source link

flatpak/xdg-portal - invalid filter: name is empty #1479

Closed eszlari closed 3 years ago

eszlari commented 3 years ago

I wanted to update Pencil2D on Flathub to KDE runtime 5.15 (with Qt 5.15). Unfortunately, this lead to a regression with the file open/save dialog, which won't show up anymore.

I made v0.6.5 compiled against Qt 5.15 available through Flathub's beta branch, so everyone can reproduce it:

$ flatpak remote-add flathub-beta https://flathub.org/beta-repo/flathub-beta.flatpakrepo
$ flatpak install flathub-beta flathub-beta
$ flatpak run org.pencil2d.Pencil2D//beta

OBS studio had a similar bug, that was fixed in this PR: https://github.com/obsproject/obs-studio/pull/2797

$ dbus-monitor --session

method call time=1601747497.234555 sender=:1.68 -> destination=org.freedesktop.portal.Desktop serial=38 path=/org/freedesktop/portal/desktop; interface=org.freedesktop.portal.FileChooser; member=SaveFile
   string "x11:69206022"
   string "Save animation"
   array [
      dict entry(
         string "current_file"
         variant             array of bytes "/home/peter/MeineAnimation.pclx" + \0
      )
      dict entry(
         string "current_filter"
         variant             struct {
               string ""
               array [
               ]
            }
      )
      dict entry(
         string "current_folder"
         variant             array of bytes "/home/peter" + \0
      )
      dict entry(
         string "directory"
         variant             boolean false
      )
      dict entry(
         string "filters"
         variant             array [
               struct {
                  string "Pencil formats "
                  array [
                     struct {
                        uint32 0
                        string "*.pclx"
                     }
                     struct {
                        uint32 0
                        string "*.pcl"
                     }
                  ]
               }
               struct {
                  string "Pencil Project "
                  array [
                     struct {
                        uint32 0
                        string "*.pclx"
                     }
                  ]
               }
               struct {
                  string "Legacy Pencil Project "
                  array [
                     struct {
                        uint32 0
                        string "*.pcl"
                     }
                  ]
               }
            ]
      )
      dict entry(
         string "handle_token"
         variant             string "qt2001422996"
      )
      dict entry(
         string "modal"
         variant             boolean true
      )
      dict entry(
         string "multiple"
         variant             boolean false
      )
   ]
error time=1601747497.234984 sender=:1.55 -> destination=:1.68 error_name=org.freedesktop.portal.Error.InvalidArgument reply_serial=38
   string "invalid filter: name is empty"
J5lx commented 3 years ago

This is a bug in Qt, not in Pencil2D, and it seems to be unrelated to the one in OBS. It does not affect Qt 5.14 because 5.14 did not support the current_filter option at all.

For the record, here’s what happens under the hood: When Qt prepares the SaveFile method call on the FileChooser interface, it goes through all of the supplied filters, “converts” them to the format required by that method, and appends them to a list. When the current filter is the one that should be initially selected in the dialog (current_filter, or selectedFilter in Qt’s terms) then it also saves a reference to the list entry it just added. In this particular case, the selected filter is the very first in the list, so after it saves that reference it continues to add more entries to the filter list. But in order to do that, the list needs to be resized, and when that happens, the selectedFilter reference becomes invalid, which results in this issue. (Edit: The relevant code is here)

Unfortunately, it looks like we can’t even work around that bug in Pencil2D without effectively removing that functionality unconditionally for everyone. Unless you really need to update the runtime to 5.15 now, it’s probably better to wait until Qt gets a proper fix for this. I’ll submit a bug report to them tomorrow.

J5lx commented 3 years ago

Bug report submitted: QTBUG-87143

eszlari commented 3 years ago

fixed upstream: https://codereview.qt-project.org/c/qt/qtbase/+/316375

back ported to runtime: https://invent.kde.org/packaging/flatpak-kde-runtime/-/merge_requests/27