-1

I have a big code of GTK2 in which I´m having troubles updating the value of an integer (in this case trigan, that its defined in the main body and callbacked to the two functions that are giving me this problem).

I intend to press the button RUN that calls the function RUN that starts displaying numbers in real time. Then, while text its running I will press STOP button that calls the function STOP, updating the value of trigan to 1.

Here is the piece of code in question:

void STOP(GtkWidget *widget, GObject *context_object_stp) 
{

  GtkEntry *trigan = g_object_get_data (context_object_stp, "trigan");


  trigan=1;


}
void RUN(GtkWidget *widget, GObject *context_object) 
{
    GtkEntry *buffer= g_object_get_data (context_object, "buffer");
    GtkEntry *wins = g_object_get_data (context_object, "wins");
    GtkEntry *trigan = g_object_get_data (context_object, "trigan");



    GtkWidget  iter;
    GtkTextIter iterscrll;
    GtkTextMark *mark;

    mark = gtk_text_buffer_get_insert(buffer);
    gtk_text_buffer_get_iter_at_mark(buffer, &iterscrll, mark);



    gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
    trigan=0;
    int i=0;
    int k=0;

    for (i=0; i<90; i=i+1)
    {
     while (trigan==1)
     {

     }
     gchar * stuff = g_strdup_printf("%d"" [%d]\n", i, trigan);
     /* Inserts buffer at position iter. */
     gtk_text_buffer_insert(buffer, &iter, stuff, -1);
     g_free(stuff);

    /* Forcing. */
    while (gtk_events_pending())
    gtk_main_iteration();
    /* Scrolls text_view the minimum distance such that mark is contained within the visible area of the widget. */
    gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(wins), mark);

     for (k=0; k<50000000; k=k+1)
     {
         k++;
     }
     k=0;
    }
}

My logic say that whit this value of trigan=1 the

   while (trigan==1)
     {

     }

should "stop" the function RUN, but it doesn't.

Help please!

Keles
  • 369
  • 1
  • 2
  • 14
  • "My logic say that whit this value of trigan=1 the while (trigan==1) should "stop" the function RUN" I'm sure it would, if such a loop actually existed in your code. `trigan` vs `triga`. Lesson learned: use sensible variable names. – Lundin Mar 31 '16 at 06:18
  • I made a mistake transcribing the main code, the variable name in all moment is trigan. I have edited the post. Thank you. – Keles Mar 31 '16 at 07:45

1 Answers1

0

yes, your assumption is correct but take a look at this extract of your code:

triga=0;
    int i=0;
    int k=0;

    for (i=0; i<90; i=i+1)
    {
     while (triga==1)
     {

     }

as you see, triga is defined, assigned to 0 an never manipoulated in between before the while... so the condition while (triga==1) is false...

that is the reason..

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • I made a mistake transcribing the main code, the variable name in all moment is trigan. I have edited the post. Thank you. – Keles Mar 31 '16 at 07:45