whoozle / android-file-transfer-linux

Android File Transfer for Linux (and macOS!)
http://whoozle.github.io/android-file-transfer-linux/
GNU Lesser General Public License v2.1
1.43k stars 120 forks source link

`vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)` #322

Open benstox opened 1 year ago

benstox commented 1 year ago

Hello,

I am getting this error when I run android-file-transfer, built at commit 5ae0221, tag continuous, version 4.3.0. I am running Ubuntu 22.04.1 LTS. It is trying to connect to a Motorola "Moto G (3rd Generation)", Android version 6.0.1.

An UI window opens with the text: "Could not open MTP session: vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)"

And I get the terminal output:

Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
upload worker started
current text color value:  0 , guessed theme:  "light"
scan
probing device...
probing device...
probing device...
probing device...
device found, opening session...
open session/device info failed:  "vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)"
open session/device info failed:  "vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)"
open session/device info failed:  "vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)"

Running aft-mtp-cli gives:

Device::Find failed:vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
leamas commented 1 year ago

Same on Fedora 36, building from source at 9967dec8ad76

EDIT: The crash only occurs on Wayland, on Xorg everything is fine.

Stacktrace:

#0  __pthread_kill_implementation
    (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0)
    at pthread_kill.c:44
#1  0x00007ffff608ec73 in __pthread_kill_internal
    (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007ffff603e986 in __GI_raise (sig=sig@entry=6)
    at ../sysdeps/posix/raise.c:26
#3  0x00007ffff60287f4 in __GI_abort () at abort.c:79
#4  0x00007ffff64a2b77 in __gnu_cxx::__verbose_terminate_handler() ()
    at ../../../../libstdc++-v3/libsupc++/vterminate.cc:95
#5  0x00007ffff64ae3bc in __cxxabiv1::__terminate(void (*)())
    (handler=<optimized out>)
    at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:48
#6  0x00007ffff64ae427 in std::terminate() ()
    at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:58
#7  0x00007ffff64ae6db in __cxxabiv1::__cxa_rethrow() ()
    at ../../../../libstdc++-v3/libsupc++/eh_throw.cc:136
#8  0x00007ffff6e857cc in QCoreApplication::notifyInternal(QObject*, QEvent*)
    (this=0x7fffffffdac0, receiver=receiver@entry=0x7fffffffd9d0, event=event@entry=0x7fffffffd8f0) at kernel/qcoreapplication.cpp:958
#9  0x00007ffff74cdac5 in QCoreApplication::sendEvent(QObject*, QEvent*)
    (event=0x7fffffffd8f0, receiver=0x7fffffffd9d0)
    at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:231
#10 QWidgetPrivate::show_helper() (this=0x848600) at kernel/qwidget.cpp:7569
#11 0x00007ffff74cf6ec in QWidget::setVisible(bool)
    (this=0x7fffffffd9d0, visible=<optimized out>) at kernel/qwidget.cpp:7791
#12 0x00000000004f2652 in QWidget::show() (this=0x7fffffffd9d0)
    at /usr/include/QtGui/qwidget.h:497
#13 0x00000000004f22c2 in main(int, char**) (argc=1, argv=0x7fffffffdc78)
    at /home/mk/src/android-file-transfer-linux/qt/main.cpp:85
leamas commented 1 year ago

Furthermore, the crash on wayland can be avoided by export GDK_BACKEND=x11 before invoking android-file-transfer

leamas commented 1 year ago

Below a simple patch which works around the issue (too lazy to make a PR, sorry, perhaps someone else is motivated)

iff --git a/qt/main.cpp b/qt/main.cpp
index 4a70feb..e5efbaf 100644
--- a/qt/main.cpp
+++ b/qt/main.cpp
@@ -25,6 +25,7 @@
 #include <QMessageBox>
 #include <QTranslator>
 #include <mtp/log.h>
+#include <stdlib.h>
 #if QT_VERSION >= 0x050000
 #      include <QGuiApplication>
 #endif
@@ -52,6 +53,10 @@ namespace

 int main(int argc, char *argv[])
 {
+       if (getenv("WAYLAND_DISPLAY")) {
+               // See #322
+               setenv("GDK_BACKEND", "x11", true);
+       }
        QApplication app(argc, argv);
        Q_INIT_RESOURCE(android_file_transfer);
llyyr commented 1 year ago

Setting GDK_BACKEND=x11 just forces aft to run under xwayland, you should instead set QT_QPA_PLATFORM=wayland to run under wayland