GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Nov 21, 2014 4:29 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Error when using gtk_text_iter_forward_search
PostPosted: Fri Nov 04, 2011 4:02 am 
Offline

Joined: Fri Nov 04, 2011 3:46 am
Posts: 2
Hello,

I'm fairly new to Gtk+ programming and was happy to find this active forum this evening. I've been struggling with isolating and understanding an error I'm getting when I attempt to use the iterators assigned when calling the gtk_text_iter_forward_search() function. I don't receive an error when I call the function and I'm able to use the start and end iterators assigned by the function earlier in my program. However, when I come to the following block of code, something seems to invalidate the iterators. When I try to call them, for instance to get text between the start and end iterators, I get this error message:

(GtkScratch:5907): Gtk-CRITICAL **: _gtk_text_btree_get_text: assertion `_gtk_text_iter_get_btree (start_orig) == _gtk_text_iter_get_btree (end_orig)' failed

I don't really understand the error message. I'm not doing anything which causes change to the buffer, which is the most obvious thing I could think that would cause an error. I'm fairly certain the error is in the following code snippet. I've tested the same functions just before this block and everything works just before this.

Code:
                    gchar* start_tag_string;
                    gchar* end_tag_string;
                    start_tag_string = malloc((tagLength+1)*sizeof(gchar));
                    end_tag_string = malloc((tagLength+2)*sizeof(gchar));
                    strcpy(start_tag_string,next->data);
                    end_tag_string[0] = '<';
                    end_tag_string[1] = '/';
                    gint i = 0;
                    for(i; i <= tagLength; i++)
                        {end_tag_string[i+2] = start_tag_string[i+1];}

                    ///Try to match end tag.
                    if(gtk_text_iter_forward_search (&end_of_start_tag,
                                                     end_tag_string,
                                                     0,
                                                     &start_of_end_tag,
                                                     &end_of_end_tag,
                                                     &endIter));
                    {
                    tmpText = gtk_text_iter_get_text(&start_of_end_tag, &end_of_end_tag); //this causes the error
                    printf(tmpText);


Top
 Profile  
 
 Post subject: Re: Error when using gtk_text_iter_forward_search
PostPosted: Fri Nov 04, 2011 4:17 am 
Offline

Joined: Fri Nov 04, 2011 3:46 am
Posts: 2
ah, maybe I posted to soon. I've isolated the problem a bit more. I'm just learning about dynamic memory allocation so I think I messed something up there. If I don't use malloc, the problem is fixed. I.e. if I replace the dynamic memory allocation with something like:

Code:
                    gchar start_tag_string[4] = "<b>";
                    gchar end_tag_string[5] = "</b>";


I don't get an error.

I have no idea why my use of malloc would cause an error, but this is the the first time I've used it so I'm probably doing something obviously wrong. However, I am able to print the variables declared using malloc and I don't get any warnings or errors from that part of my code.

Time to do some more reading and head scratching.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group