title: Assertion Failed at method: gee_array_list_real_get
body: <p>I think I fixed this error but I want to be certain I did it the right way.
  Also I am not sure why is it happening this way.</p>
  
  <p>Code before fix:</p>
  
  <pre class="lang-cs prettyprint-override"><code>private Gee.ArrayList&lt;Gtk.Widget&gt; menuButtons;
  
  // Some other code here
  
  public override void remove (Gtk.Widget widget) {
      if (widget in menuButtons) {
          widget.unparent ();
          menuButtons.remove ( widget ); // Look at this method call
          if (this.get_visible () &amp;&amp; widget.get_visible ()) {
              this.queue_resize_no_redraw ();
          }
      }
  }
  </code></pre>
  
  <p>The code causes:</p>
  
  <pre><code>ERROR:arraylist.c:957:gee_array_list_real_get: assertion failed: (index &lt; _size)
  ./run: line 3: 11054 Aborted                 (core dumped) ./bin
  </code></pre>
  
  <p>Code after fix:</p>
  
  <pre class="lang-cs prettyprint-override"><code>    private Gee.ArrayList&lt;Gtk.Widget&gt; menuButtons;
  
      // Some other code here
  
      public override void remove (Gtk.Widget widget) {
          if (widget in menuButtons) {
              widget.unparent ();
              if (this.get_visible () &amp;&amp; widget.get_visible ()) {
                  this.queue_resize_no_redraw ();
                  menuButtons.remove ( widget ); // Moved method call here
              }
          }
      }
  </code></pre>
  
  <p>And now it works, I am not sure but it might be something to do with remove method being called asynchronously, is it?</p>
  
  <p>Any good explanation?
  Is it a correct fix of a problem?</p>
  
  <p>@After checking the code again I am certain that it is not a correct fix of my problem because menuButtons.remove ( widget ); never gets called in my case. The widget stays in the list and that is unwanted behaviour.</p>
  
  <p>MVCE:</p>
  
  <p>MyContainer.vala</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class MyContainer : Gtk.Container {
    // ArrayList for storing menu buttons
    private Gee.ArrayList&lt;Gtk.Widget&gt; menuButtons;
  
    public MyContainer () {
      base.set_has_window (false);
      menuButtons = new Gee.ArrayList&lt;Gtk.Widget&gt; ();
    }
  
    public override void add (Gtk.Widget widget) {
      widget.set_parent (this);
      menuButtons.add (widget);
    }
  
    public override void remove (Gtk.Widget widget) {
      if (widget in menuButtons) {
        widget.unparent ();
        menuButtons.remove ( widget ); // After removing the widget from the List I get "assertion failed error"
        if (this.get_visible () &amp;&amp; widget.get_visible ()) {
          this.queue_resize_no_redraw ();
        }
      }
    }
  
    public override void forall_internal (bool include_internals, Gtk.Callback callback) {
      foreach (var widget in menuButtons) {
        callback (widget);
      }
    }
  }
  </code></pre>
  
  <p>SimpleGtkApplication.vala</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class SimpleGtkApplication : Gtk.Application {
  
    public SimpleGtkApplication () {
      Object (application_id: "simple.gtk.application", flags: ApplicationFlags.FLAGS_NONE);
    }
  
    protected override void activate () {
      Gtk.ApplicationWindow window = new Gtk.ApplicationWindow (this);
      window.set_default_size (800, 600);
      window.title = "SimpleGtkApplication";
  
      Gtk.Container container = new MyContainer ();
      container.add ( new Gtk.Button.with_label ("Button 1") );
      container.add ( new Gtk.Button.with_label ("Button 2") );
  
      window.add ( container );
      window.show_all ();
    }
  
    public static int main (string[] args) {
      SimpleGtkApplication app = new SimpleGtkApplication ();
      return app.run (args);
    }
  
  }
  </code></pre>
  
  <p>Compile with: <code>--pkg=gtk+-3.0 --pkg=gee-0.8</code></p>