Re: Error in gtk_text_buffer_insert()?



I made a little progress on this today. Here's my new network_read().

When I run the app now, it doesn't segfault, but I get this output:

(panache:14915): Gtk-CRITICAL **: file gtktextbuffer.c: line 2469
(gtk_text_buffer_get_end_iter): assertion `iter != NULL' failed

(panache:14915): Gtk-CRITICAL **: file gtktextbuffer.c: line 508
(gtk_text_buffer_insert): assertion `iter != NULL' failed

How do I go about setting up the iter properly?

gint network_read ( gpointer data,
                    gint source,
                    GdkInputCondition condition)
{
  gchar buff[1025];
  int read_bytes = 1024;
  int got_bytes;
  gint local_data = GPOINTER_TO_INT(data);

  gtk_text_buffer_get_end_iter(
    gtk_text_view_get_buffer(
      GTK_TEXT_VIEW(WorldList[(int)local_data].output_text)
    ),
    WorldList[(int)local_data].output_end_iter
  );

  got_bytes = recv(source, buff, read_bytes, 0);

  if (got_bytes > 0) {
    gtk_text_buffer_insert(
      gtk_text_view_get_buffer(
        GTK_TEXT_VIEW(WorldList[(int)local_data].output_text)
      ),
      WorldList[(int)local_data].output_end_iter,
      _(buff),
      (gint)got_bytes
    );
    return TRUE;
  } else {
    gdk_input_remove(WorldList[(int)local_data].network_read_handler);
    return FALSE;
  }
}

Matthew Walker said:
Allin Cottrell said:
On Sun, 28 Jul 2002, Matthew Walker wrote:

I'm working on converting a project from GTK 1.2 to 2.0, and I'm
running into a segfault while using gtk_text_buffer_insert(). I've
included the function where the segfault is occuring. If you need more
information, let me know.

(If you see any other problems, feel free to point them out too...)

This is a read handler on a network socket.

gint network_read ( gpointer data,
                    gint source,
                    GdkInputCondition condition)
{
  gchar buff[1025];
  int read_bytes = 1024;
  int got_bytes;

  GtkTextView *output_view = (GtkTextView
*)WorldList[(int)data].output_text; GtkTextBuffer *output_buffer =
gtk_text_view_get_buffer(output_view);
gtk_text_buffer_get_end_iter(output_buffer,
                               WorldList[(int)data].output_end_iter);

Couple of thoughts:

Can you really do that (int) cast on "data"?  Perhaps you need
GINT_TO_POINTER() in the caller and GPOINTER_TO_INT() in
network_read()?

I've never had to do it before, but I will add that in, since it sounds
like a Good Idea (tm).


What is the type of WorldList[].output_end_iter?  From the context it
has to be pointer-to-GtkTextIter, and storage for the Iter must have
been allocated somehow.

Here's the relevant bit of code that defines WorldList:

struct WorldData {
      GtkWidget *io_pane;
      GtkWidget *output_scroller;
      GtkWidget *output_text;
      GtkWidget *input_scroller;
      GtkWidget *input_text;
      GtkWidget *world_name;
      GtkWidget *editor_name;

      GString *DisplayName;
      GString *FileName;
      GString *WorldDomain;
      gint WorldPort;
      GString *CharacterName;
      GString *Password;
      gint AutoConnect;
      GString *WorldComment;
      GList *command_history;
      gint historyindex;
      GString *storedcommand;
      gboolean changed;
      gint WorldType;
      int sockfd;
      struct sockaddr_in my_addr;
      gint network_read_handler;
      GtkTextIter *output_end_iter;
};
struct WorldData WorldList[32];

(A pointer to a /good/ How-To on dynamically allocating memory for this
kind of array would be VERY much appreciated. I don't wont to do it
staticaly, but I can't grok malloc())


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]