inda19plusplus / logik

Logisim clone
MIT License
2 stars 5 forks source link

[WIP] File- manager & structure xP #22

Closed violaso closed 4 years ago

violaso commented 4 years ago

…GTK violation bug freezes application :(

its 4 o'clock noobs lol

weerox commented 4 years ago

I fetched this PR and tried to recreate the bug and found another one, I can't see files (only folders) and when pressing the "Cancel" button the whole application exits.

violaso commented 4 years ago

Initial clue

This might help with the bug.

Note that Dispose()ing a widget in GTK# doesn't Destroy() it in GTK# -- a historical design accident, preserved for backwards-compatibility. However, if you use a custom dialog subclass you can override Dispose to also Destroy the dialog.

It's important to note that when overriding Dispose in a custom dialog, one has to call Destroy before base.Dispose

Should we write a custom FileChooserDialog class? It may be overcomplicated.

Extended research

I've tried calling fcd.Destroy before Dispose, which is declared as [deprecated] void Widget.Destroy. The Mono Documentation doesn't mention this method, but the Gnome Gtk3 documentation does.

According to the Mono Documentation on the Gtk.FileChooserDialog class:

This widget works by putting a Gtk.FileChooserWidget inside a Gtk.Dialog. It exposes the Gtk.FileChooser interface, so you can use all of the Gtk.FileChooser functions on the file chooser dialog as well as those for Gtk.Dialog.

According to the Gnome Gtk3 documentation:

When a widget is destroyed all references it holds on other objects will be released:

  • if the widget is inside a container, it will be removed from its parent

You should typically call this function on top level widgets, and rarely on child widgets.

Destroy is implemented by the Dialog class, but cannot be accessed from the FileChooserDialog class.

Confusion

It seems like all Destroy methods are obsolete for the benefit of Dispose, but Dispose "doesn't Destroy() it in GTK#".

Conclusion

There might be a reason that Dispose barely is mentioned at all on the web; gtk is broken af and we are the only people using it.

Thanks for reading my rant!

NogginBops commented 4 years ago

I agree that gtksharp (and gtk+) is a mess, but it's not it's definitely not only us that are using it. It's used for a lot of high profile applications like GIMP (it's namesake), Inkscape, and a lot of linux desktop environments. MonoDevelop is also a notable example of gtksharp.

violaso commented 4 years ago

Bug definition

The application's CPU usage goes haywire after calling fcd.Run() and (or while) exiting the EventHandler. If the application is started without debugging (Debug > Start Without Debugging), the following is printed to the debug console.

Exception code=0xc0000005 flags=0x0 at 0x000000006786F835. Access violation - attempting to read data at address 0x0000000000000030
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Gtk.Application.Run()
   at LogikUI.Program.Main()

The error is explained as:

Access violation reading location 0x00000000 means that you're derefrencing a pointer that hasn't been initialized and therefore has garbage values.

An AccessViolationException can occur only in unsafe managed code or when verifiable managed code interacts with unmanaged code.

Underlying error

image

Console error log (a lot)

```txt (LogikUI:19960): Gtk-CRITICAL **: 21:40:19.612: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed (LogikUI:19960): GLib-CRITICAL **: 21:40:56.138: g_variant_ref_sink: assertion 'value != NULL' failed (LogikUI:19960): Gtk-CRITICAL **: 21:44:07.227: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed (LogikUI:19960): Gtk-CRITICAL **: 21:44:16.569: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed (LogikUI:19960): Gtk-CRITICAL **: 21:44:19.615: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed (LogikUI:19960): Gtk-CRITICAL **: 21:44:21.326: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed (LogikUI:19960): Gtk-CRITICAL **: 21:44:23.034: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed Successfully read and parsed project file C:\Users\User\Documents\KTH\INDA\Mjukvaruprojekt\logik\src\LogikUI\File\test.xml. (LogikUI:19960): Gtk-CRITICAL **: 21:44:50.465: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed - wires: System.Collections.Generic.List`1[LogikUI.Circuit.Wire] (LogikUI:19960): Gtk-CRITICAL **: 21:44:56.399: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed - components: System.Collections.Generic.List`1[LogikUI.Simulation.Gates.IInstance] (LogikUI:19960): Gtk-CRITICAL **: 21:45:14.280: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed - labels: System.Collections.Generic.List`1[LogikUI.Circuit.TextLabel] (LogikUI:19960): Gtk-CRITICAL **: 21:45:17.211: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:19.833: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:21.649: gtk_file_chooser_widget_get_current_name: assertion 'priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.228: gtk_window_get_accept_focus: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.246: gtk_widget_get_accessible: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.265: gtk_file_chooser_get_action: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.280: gtk_dialog_get_action_area: assertion 'GTK_IS_DIALOG (dialog)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.307: gtk_container_forall: assertion 'GTK_IS_CONTAINER (container)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.329: gtk_widget_get_allocated_baseline: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.344: gtk_widget_get_allocated_height: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.358: gtk_widget_get_allocated_width: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.372: gtk_widget_get_allocation: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.385: gtk_widget_get_app_paintable: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.398: gtk_window_get_application: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.415: gtk_window_get_attached_to: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.431: gtk_container_get_border_width: assertion 'GTK_IS_CONTAINER (container)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.453: gtk_widget_get_can_default: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.464: gtk_widget_get_can_focus: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.476: gtk_bin_get_child: assertion 'GTK_IS_BIN (bin)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.489: _gtk_widget_get_preferred_size_and_baseline: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.502: gtk_widget_get_child_visible: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.514: gtk_container_foreach: assertion 'GTK_IS_CONTAINER (container)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.527: gtk_widget_get_clip: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): GLib-GObject-CRITICAL **: 21:45:23.538: g_object_get_property: assertion 'G_IS_OBJECT (object)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.550: gtk_widget_get_composite_name: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.563: gtk_dialog_get_content_area: assertion 'GTK_IS_DIALOG (dialog)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.598: gtk_file_chooser_get_create_folders: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.613: gtk_file_chooser_get_current_folder: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.626: gtk_file_chooser_get_current_folder_file: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.642: gtk_file_chooser_get_current_folder_uri: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.656: gtk_file_chooser_get_current_name: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.692: gtk_window_get_decorated: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): GLib-GObject-CRITICAL **: 21:45:23.722: g_object_get_property: assertion 'G_IS_OBJECT (object)' failed (LogikUI:19960): GLib-GObject-CRITICAL **: 21:45:23.735: g_object_get_property: assertion 'G_IS_OBJECT (object)' failed (LogikUI:19960): GLib-GObject-CRITICAL **: 21:45:23.738: g_object_get_property: assertion 'G_IS_OBJECT (object)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.752: gtk_window_get_default_widget: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): GLib-GObject-CRITICAL **: 21:45:23.767: g_object_get_property: assertion 'G_IS_OBJECT (object)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.779: gtk_window_get_deletable: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.792: gtk_window_get_destroy_with_parent: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.805: gtk_widget_get_direction: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.817: gtk_widget_get_display: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.831: gtk_file_chooser_get_do_overwrite_confirmation: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.844: gtk_widget_get_double_buffered: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.855: gtk_widget_get_events: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): GLib-GObject-CRITICAL **: 21:45:23.867: g_object_get_property: assertion 'G_IS_OBJECT (object)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.880: gtk_file_chooser_get_extra_widget: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.897: gtk_file_chooser_get_file: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.910: gtk_file_chooser_get_filename: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.924: gtk_file_chooser_get_filenames: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.939: gtk_file_chooser_get_files: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.952: gtk_file_chooser_get_filter: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.966: gtk_file_chooser_list_filters: assertion 'GTK_IS_FILE_CHOOSER (chooser)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.979: gtk_window_get_focus: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:23.993: gtk_container_get_focus_chain: assertion 'GTK_IS_CONTAINER (container)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.006: gtk_container_get_focus_child: assertion 'GTK_IS_CONTAINER (container)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.021: gtk_container_get_focus_hadjustment: assertion 'GTK_IS_CONTAINER (container)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.050: gtk_widget_get_focus_on_click: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.062: gtk_window_get_focus_on_map: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.082: gtk_container_get_focus_vadjustment: assertion 'GTK_IS_CONTAINER (container)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.097: gtk_window_get_focus_visible: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.109: gtk_widget_get_font_map: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.122: gtk_widget_get_font_options: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.134: gtk_widget_get_frame_clock: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.146: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.159: gtk_window_get_gravity: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.179: gtk_widget_get_halign: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.192: gtk_widget_has_default: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.203: gtk_widget_has_focus: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.215: gtk_widget_has_grab: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.227: gtk_window_has_group: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.241: gtk_widget_has_rc_style: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.252: gtk_window_get_has_resize_grip: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.264: gtk_widget_has_screen: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.275: gtk_widget_get_has_tooltip: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): GLib-GObject-CRITICAL **: 21:45:24.288: g_object_get_property: assertion 'G_IS_OBJECT (object)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.299: gtk_widget_has_visible_focus: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.310: gtk_widget_get_has_window: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.324: gtk_dialog_get_header_bar: assertion 'GTK_IS_DIALOG (dialog)' failed (LogikUI:19960): GLib-GObject-CRITICAL **: 21:45:24.338: g_object_get_property: assertion 'G_IS_OBJECT (object)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.351: gtk_widget_get_hexpand: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.362: gtk_widget_get_hexpand_set: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.374: gtk_window_get_hide_titlebar_when_maximized: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.388: gtk_window_get_icon: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.400: gtk_window_get_icon_list: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.412: gtk_window_get_icon_name: assertion 'GTK_IS_WINDOW (window)' failed (LogikUI:19960): GLib-GObject-CRITICAL **: 21:45:24.432: g_object_get_property: assertion 'G_IS_OBJECT (object)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.445: gtk_widget_is_composited: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.456: gtk_widget_is_drawable: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.467: gtk_widget_is_focus: assertion 'GTK_IS_WIDGET (widget)' failed (LogikUI:19960): Gtk-CRITICAL **: 21:45:24.480: gtk_widget_get_mapped: assertion 'GTK_IS_WIDGET (widget)' failed ```

NogginBops commented 4 years ago

My recommendation would be to look at how gtk+ 3 tutorials do file choosers and basically copy what those do. And if that doesn't work it there might be something gtksharp related that's happening.

violaso commented 4 years ago

(potential) Bug cause

Maybe this has something to do with our issue.

gtk widgets have a built in assert function. If a callback of such a widget lasts to long to return, the widget will throw an acception and GXSM will crash. So using gtk_dialog_run() inside a callback is a no-no as you have to click on the dialog within 1 second or so.

The problem is not the dialog itself but the run command. By using run the the code gets into a locking loop and therefor the rest of Gxsm stands still until the user decided to press a button. This leads to the timeout.

Observe that our FileChooserDialog actually stays open for roughly 1 second before the application crashes. See the 'Underlying error' under the bug definition, which confirms the assertion-timeout theory.

Although, our issue persists when using Show or ShowAll with Hide, instead of Run.

violaso commented 4 years ago

Bug solved

The cause may forever be a mystery, but the fault didn't lie with Dialog. Instead, let me quote a somewhat lucky person who stumbled upon the solution.

Linux personer säger att man inte ska göra dumma saker, medan andra tycker att det det är saker som man uppenbarligen borde kunna göra.

Big takeaway

NEVER EVER EVER(!) OPEN A Dialog IN A Selected CALLBACK!

violaso commented 4 years ago

FileManager continues on #42

NogginBops commented 4 years ago

This has been merged with @axel-kaliff s pr #42 . Closing this.