Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropping files on Gtk/Linux/Wayland not working and crashing the application #1812

Closed
ManuelHu opened this issue Oct 30, 2020 · 4 comments · Fixed by #2194
Closed

Dropping files on Gtk/Linux/Wayland not working and crashing the application #1812

ManuelHu opened this issue Oct 30, 2020 · 4 comments · Fixed by #2194
Labels
Milestone

Comments

@ManuelHu
Copy link
Contributor

Expected Behavior

Drop is working, not crashing the application & returning the file Uris.

Actual Behavior

e.Data.Uris is null despite e.Data.ContainsUris being true. After the Drop event handler had been executed, the application crashes with the following stack trace.

Marshaling drag-drop signal
Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
  at Eto.GtkSharp.Forms.GtkControl`3+GtkControlConnector[TControl,TWidget,TCallback].HandleDragDrop (System.Object o, Gtk.DragDropArgs args) [0x0006d] in <92af4fa169514fde8bca8cf01b10173d>:0 
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 
   --- End of inner exception stack trace ---
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0007e] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:409 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /builddir/build/BUILD/mono-6.12.0.90/external/corefx/src/Common/src/CoreLib/System/Reflection/MethodBase.cs:53 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e1] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System/Delegate.cs:465 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System/MulticastDelegate.cs:67 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System/Delegate.cs:410 
  at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00034] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00009] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at GLib.SignalClosure.MarshalCallback (System.IntPtr raw_closure, System.IntPtr return_val, System.UInt32 n_param_vals, System.IntPtr param_values, System.IntPtr invocation_hint, System.IntPtr marshal_data) [0x00136] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at GLib.ExceptionManager.RaiseUnhandledException (System.Exception e, System.Boolean is_terminal) [0x00000] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at GLib.SignalClosure.MarshalCallback (System.IntPtr raw_closure, System.IntPtr return_val, System.UInt32 n_param_vals, System.IntPtr param_values, System.IntPtr invocation_hint, System.IntPtr marshal_data) [0x00000] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at System.Object.wrapper_native_0x7f6b355e9ae0 (System.IntPtr ) [0x00000] in <6de68d9ed0b943838b4ddc538c95c31e>:0 
  at Gtk.Dialog.Run () [0x00000] in <1e6f8c28e50f45219882c5d697fcfc22>:0 
  at Eto.GtkSharp.Forms.DialogHandler.ShowModal () [0x00000] in <92af4fa169514fde8bca8cf01b10173d>:0 
  at Eto.Forms.Dialog.ShowModal () [0x00000] in <8933e1bfea764347a7e19cc64c170cea>:0 
  at Eto.Forms.Dialog.ShowModal (Eto.Forms.Control owner) [0x00000] in <8933e1bfea764347a7e19cc64c170cea>:0 
  at FotostudioUpload.MainForm.DropButton_Click (System.Object sender, System.EventArgs e) [0x0007e] in fpledit-src/FotostudioUpload/MainForm.xeto.cs:124 
  at Eto.PropertyStore.TriggerEvent[T] (System.Object key, System.Object sender, T args) [0x00000] in <8933e1bfea764347a7e19cc64c170cea>:0 
  at Eto.Forms.Button.OnClick (System.EventArgs e) [0x00000] in <8933e1bfea764347a7e19cc64c170cea>:0 
  at Eto.Forms.Button+Callback.OnClick (Eto.Forms.Button widget, System.EventArgs e) [0x00000] in <8933e1bfea764347a7e19cc64c170cea>:0 
  at Eto.GtkSharp.Forms.Controls.ButtonHandler`3+ButtonConnector[TControl,TWidget,TCallback].HandleClicked (System.Object sender, System.EventArgs e) [0x00000] in <92af4fa169514fde8bca8cf01b10173d>:0 
  at System.Reflection.RuntimeMethodInfo.InternalInvoke (System.Reflection.RuntimeMethodInfo , System.Object , System.Object[] , System.Exception& ) [0x00000] in <6de68d9ed0b943838b4ddc538c95c31e>:0 
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /builddir/build/BUILD/mono-6.12.0.90/external/corefx/src/Common/src/CoreLib/System/Reflection/MethodBase.cs:53 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e1] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System/Delegate.cs:465 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System/MulticastDelegate.cs:67 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System/Delegate.cs:410 
  at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at GLib.SignalClosure.MarshalCallback (System.IntPtr raw_closure, System.IntPtr return_val, System.UInt32 n_param_vals, System.IntPtr param_values, System.IntPtr invocation_hint, System.IntPtr marshal_data) [0x00000] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at System.Object.wrapper_native_0x7f6b35684170 () [0x00000] in <6de68d9ed0b943838b4ddc538c95c31e>:0 
  at Gtk.Application.Run () [0x00000] in <1e6f8c28e50f45219882c5d697fcfc22>:0 
  at Eto.GtkSharp.Forms.ApplicationHandler.Run () [0x00000] in <92af4fa169514fde8bca8cf01b10173d>:0 
  at Eto.Forms.Application.Run (Eto.Forms.Form mainForm) [0x00000] in <8933e1bfea764347a7e19cc64c170cea>:0 
  at FotostudioUpload.Program.Main (System.String[] args) [0x00062] in fpledit-src/FotostudioUpload/Program.cs:30 

Steps to Reproduce the Problem

  1. Create a form with AllowDrop, set DragEffect to Copy in DragEnter
  2. Access e.Data.Uris in DragDrop-event
  3. Drop file from nautilus (default file manager for GNOME based Desktops) => crash

Only reproducible with dropping files, not other objects (I tested dropping text)

  • Also reproducible with the test application by dropping a file on the designated drop zone. This (additionally) freezes the test app for ~ 15 seconds spitting out Gtk warnings (before crashing):
  • Note: In the test application I managed to get the right data, but not reproducible. It depends on how long you wait to release the mouse pointer. When you release the button after the first warning appears, it sometimes works and does not crash. Sometimes...
(Eto.Test.Gtk:55023): Gtk-WARNING **: 20:19:25.081: You must override the default 'drag_data_received' handler on GtkTreeView when using models that don't support the GtkTreeDragDest interface and enabling drag-and-drop. The simplest way to do this is to connect to 'drag_data_received' and call g_signal_stop_emission_by_name() in your signal handler to prevent the default handler from running. Look at the source code for the default handler in gtktreeview.c to get an idea what your handler should do. (gtktreeview.c is in the GTK source code.) If you're using GTK from a language other than C, there may be a more natural way to override default handlers, e.g. via derivation.

Code that Demonstrates the Problem

var df = new Dialog();
df.Title = "Test";
df.AllowDrop = true;
df.Size = new Size(400, 200);
df.DragDrop += (s, e) =>
{
    Uri[] files = e.Data.Uris;
};
df.DragEnter += (s, e) =>
{
    e.Effects = DragEffects.Copy;
};
df.ShowModal(this);

Specifications

  • Version: current prerelease
  • Platform(s): Gtk
  • Operating System(s): Fedora 33, Wayland Session (GNOME 3.38.1)
@ManuelHu
Copy link
Contributor Author

An additional note: accessing e.Data.Uris from DragEnter does not lead to the crash... But still returns null

@ManuelHu
Copy link
Contributor Author

ManuelHu commented Oct 31, 2020

Got another (possibly related crash)

Marshaling drag-motion signal
Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
  at Eto.GtkSharp.Forms.GtkControl`3+GtkControlConnector[TControl,TWidget,TCallback].HandleDragMotion (System.Object o, Gtk.DragMotionArgs args) [0x00074] in <dc935eccd0934782b645729b31b542ea>:0 
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 
   --- End of inner exception stack trace ---
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0007e] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:409 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /builddir/build/BUILD/mono-6.12.0.90/external/corefx/src/Common/src/CoreLib/System/Reflection/MethodBase.cs:53 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e1] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System/Delegate.cs:465 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System/MulticastDelegate.cs:67 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in /builddir/build/BUILD/mono-6.12.0.90/mcs/class/corlib/System/Delegate.cs:410 
  at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00034] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00009] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at GLib.SignalClosure.MarshalCallback (System.IntPtr raw_closure, System.IntPtr return_val, System.UInt32 n_param_vals, System.IntPtr param_values, System.IntPtr invocation_hint, System.IntPtr marshal_data) [0x00136] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at GLib.ExceptionManager.RaiseUnhandledException (System.Exception e, System.Boolean is_terminal) [0x00000] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at GLib.SignalClosure.MarshalCallback (System.IntPtr raw_closure, System.IntPtr return_val, System.UInt32 n_param_vals, System.IntPtr param_values, System.IntPtr invocation_hint, System.IntPtr marshal_data) [0x00000] in <7899125c45b94e45a5c6367fe303fbb7>:0 
  at System.Object.wrapper_native_0x7f9981460170 () [0x00000] in <6de68d9ed0b943838b4ddc538c95c31e>:0 
  at Gtk.Application.Run () [0x00000] in <1e6f8c28e50f45219882c5d697fcfc22>:0 
  at Eto.GtkSharp.Forms.ApplicationHandler.Run () [0x00000] in <dc935eccd0934782b645729b31b542ea>:0 
  at Eto.Forms.Application.Run (Eto.Forms.Form mainForm) [0x00000] in <ffa757a5efbd4633b543b3231ce87698>:0 
  at FotostudioUpload.Program.Main (System.String[] args) [0x00062] in fpledit-src/FotostudioUpload/Program.cs:30 

Code to reproduce:

public class MyForm : Form 
{

public MyForm() {
    this.AllowDrop = true;
    this.Size = new Size(800, 800);
}

private bool dragFormOpen = false;

protected override void OnDragEnter(DragEventArgs e)
{
    e.Effects = DragEffects.None;
    if (!dragFormOpen)
        DragForm();
    base.OnDragEnter(e);
}

void DragForm()
{
    dragFormOpen = true;
    var df = new Dialog();
    df.Title = "Test";
    df.AllowDrop = true;
    df.Size = new Size(400, 200);
    df.DragDrop += (s, e) =>
    {
        Uri[] files = e.Data.Uris;
    };
    df.DragEnter += (s, e) =>
    {
        e.Effects = DragEffects.Copy;
    };
    df.ShowModal(this);
}
}
  • Drag a file onto the main form - the "dropzone" window opens.
  • Do not enter the dropzone (then the crash above would happen...)
  • Drag the file out of the main window again (without attempting to drop it) => Crash

@cwensley
Copy link
Member

cwensley commented Nov 4, 2020

Awesome, thanks for all the details!

@julian-baumann
Copy link

I'm pretty sure this issue still exists in v2.7.0.
I am still experiencing the exact same error. When I drag a file into the application, the property dropEvent.Data.Uris is still null, despite dropEvent.Data.ContainsUris == true, then the application crashes with the same exception.
I double checked the versions, to be sure I'm really using the latest 2.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants