Re: Error in gtk_text_buffer_insert()?



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())





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