GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Oct 25, 2014 12:40 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: IA__gtk_main_quit: assertion `main_loops != NULL' failed
PostPosted: Tue Jan 03, 2012 3:51 pm 
Offline
Familiar Face

Joined: Mon Oct 17, 2011 10:18 am
Posts: 26
Hello All,

I will be more than grateful if you could find time for answering me.

General:
I am writing a GUI, in which I receive real time video from several cameras of a robot (using ROS).

The problem:
Everything works perfectly, until the stage I want to close the top level window (by clicking the X button).
The window is destroyed, but I receive this critical warning:
Quote:
Gtk-CRITICAL **: IA__gtk_main_quit: assertion `main_loops != NULL' failed

My analysis:
I connect the "destroy" signal to the function "gtk_main_quit" in the next way:
Code:
g_signal_connect( G_OBJECT(globalTopLevelWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL );

After analysing the code I have inferred that this warning is thrown by this line of code:
Code:
g_return_if_fail (main_loops != NULL)
which is the first line of "gtk_main_quit" function.
And it means that there are no main loops executing when the process is in this line of code.

The questions:
1. Actually I donĀ“t understand why the warning exists? It is OK, the assertion should fail. Am I right? Should I ignore this? Hmm...:-\
2. How can I fix this?

Thanks in advance,
Felix.

P.S. The code of my main (for your convenience):
Code:
int main(int argc, char **argv)
{
   ros::init(argc, argv, "image_listener");
    ros::NodeHandle nh;
   ros::Rate loop_rate(100);                                                                   // Rate class instance.   
   ImageManagmentStruct LeftCameraImageStruct, RightCameraImageStruct, KinectImageStruct;      // Structs for image menagment.      
   
    // Getting the resizing parameter from the launch file.
    if ( !nh.getParam("resizing_factor", globalResizingFactor) )
    {
        ROS_ERROR ("The resizing factor was not loaded succesfully. Aborting...\n");
        ros::shutdown();
    }

    // Initializing the image/camera data structures.   
   dataStructuresInitialization ( &LeftCameraImageStruct, &RightCameraImageStruct, &KinectImageStruct );
       
    // GTK library initialization
   gtk_init ( &argc, &argv );

    // Creating a top level window and connecting it to a sygnal.   
    createMainInterfaceWindow ();
   
    // Creating a fixed container, which will hold all the widgets of the GUI.
    createFixedContainer ();
   
    // Creating a GtkGrid widget, which will contain all the images.
    createGtkTable ();
   
    // Attaching the created table to the Container.
    gtk_fixed_put (GTK_FIXED (pGlobalFixedContainer), pGlobalGtkTable, IMAGES_HORIZONTAL_PLACEMENT, IMAGES_VERTIACL_PLACEMENT);
     
   // Subscribing in order to receive images.
   ros::Subscriber subLeft = nh.subscribe<sensor_msgs::Image> ("leftCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[0]));    
    ros::Subscriber subRight = nh.subscribe<sensor_msgs::Image> ("rightCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[1]));
    ros::Subscriber subKinect = nh.subscribe<sensor_msgs::Image> ("kinectCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[2]));
      
    while ( ros::ok() )
    {
      // Showing the main window, with the attached image.
      if ( GTK_IS_WIDGET (globalTopLevelWindow) )
      {
         gtk_widget_show_all ( globalTopLevelWindow );       
      }
      else
      {
           ROS_INFO ("The top level window of the application was closed...Exiting the program.\n");
           return 0;
      }
      
      // Allowing "imageCallback" to be called.
      ros::spinOnce();
      
              // Running the main GTK iteration loop.
      gtk_main_iteration_do(0);   
         
      // Sleep
       loop_rate.sleep ();   
    } 
    return 0;
}


Top
 Profile  
 
 Post subject: Re: IA__gtk_main_quit: assertion `main_loops != NULL' failed
PostPosted: Tue Jan 03, 2012 8:40 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
return_if_fail (main_loops!=NULL) returning means you have no main loops running.
This is the case as you have called gtk_main_iteration_do which only runs once and then quits (leaving no main loops). By the time you click the x your program will be running the sleep command rather than the gtk_main loop. You should use gtk_main rather than gtk_main_iteration_do


Top
 Profile  
 
 Post subject: Re: IA__gtk_main_quit: assertion `main_loops != NULL' failed
PostPosted: Wed Jan 04, 2012 8:01 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 764
Location: UK
Hi,

This is how I would get around your problem. First it avoids the use of a macro that is really for the implementation of GtkWidget. By using a combination of 'gtk_main()' and 'g_timeout_add()' I have been able to avoid having to busy loop, but still have ROS called at a rate of 100Hz. Also I am not forcing the system to sleep and do no work so you should get a more snappier GUI response.

Code:
gboolean do_ros(gpointer data)
{
    if (ros::ok())
        ros::spinOnce();
    else
        gtk_main_quit();

    return TRUE;
}

int main(int argc, char **argv)
{
   ros::init(argc, argv, "image_listener");
    ros::NodeHandle nh;
   ImageManagmentStruct LeftCameraImageStruct, RightCameraImageStruct, KinectImageStruct;      // Structs for image menagment.     
   
    // Getting the resizing parameter from the launch file.
    if ( !nh.getParam("resizing_factor", globalResizingFactor) )
    {
        ROS_ERROR ("The resizing factor was not loaded succesfully. Aborting...\n");
        ros::shutdown();
    }

    // Initializing the image/camera data structures.   
   dataStructuresInitialization ( &LeftCameraImageStruct, &RightCameraImageStruct, &KinectImageStruct );
       
    // GTK library initialization
   gtk_init ( &argc, &argv );

    // Creating a top level window and connecting it to a sygnal.   
    createMainInterfaceWindow ();
   
    // Creating a fixed container, which will hold all the widgets of the GUI.
    createFixedContainer ();
   
    // Creating a GtkGrid widget, which will contain all the images.
    createGtkTable ();
   
    // Attaching the created table to the Container.
    gtk_fixed_put (GTK_FIXED (pGlobalFixedContainer), pGlobalGtkTable, IMAGES_HORIZONTAL_PLACEMENT, IMAGES_VERTIACL_PLACEMENT);
     
   // Subscribing in order to receive images.
   ros::Subscriber subLeft = nh.subscribe<sensor_msgs::Image> ("leftCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[0]));   
    ros::Subscriber subRight = nh.subscribe<sensor_msgs::Image> ("rightCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[1]));
    ros::Subscriber subKinect = nh.subscribe<sensor_msgs::Image> ("kinectCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[2]));


    g_timeout_add(1000 / 100, do_ros, NULL);

    gtk_widget_show_all(globalTopLevelWindow);

    gtk_main();

    ROS_INFO ("The top level window of the application was closed...Exiting the program.\n");

    return 0;
}

_________________
E.


Top
 Profile  
 
 Post subject: Re: IA__gtk_main_quit: assertion `main_loops != NULL' failed
PostPosted: Thu Jan 05, 2012 11:36 am 
Offline
Familiar Face

Joined: Mon Oct 17, 2011 10:18 am
Posts: 26
Paul Childs wrote:
return_if_fail (main_loops!=NULL) returning means you have no main loops running.
This is the case as you have called gtk_main_iteration_do which only runs once and then quits (leaving no main loops). By the time you click the x your program will be running the sleep command rather than the gtk_main loop. You should use gtk_main rather than gtk_main_iteration_do


Paul, thank you for your answer.


Top
 Profile  
 
 Post subject: Re: IA__gtk_main_quit: assertion `main_loops != NULL' failed
PostPosted: Thu Jan 05, 2012 11:37 am 
Offline
Familiar Face

Joined: Mon Oct 17, 2011 10:18 am
Posts: 26
errol wrote:
Hi,

This is how I would get around your problem. First it avoids the use of a macro that is really for the implementation of GtkWidget. By using a combination of 'gtk_main()' and 'g_timeout_add()' I have been able to avoid having to busy loop, but still have ROS called at a rate of 100Hz. Also I am not forcing the system to sleep and do no work so you should get a more snappier GUI response.

Code:
gboolean do_ros(gpointer data)
{
    if (ros::ok())
        ros::spinOnce();
    else
        gtk_main_quit();

    return TRUE;
}

int main(int argc, char **argv)
{
   ros::init(argc, argv, "image_listener");
    ros::NodeHandle nh;
   ImageManagmentStruct LeftCameraImageStruct, RightCameraImageStruct, KinectImageStruct;      // Structs for image menagment.     
   
    // Getting the resizing parameter from the launch file.
    if ( !nh.getParam("resizing_factor", globalResizingFactor) )
    {
        ROS_ERROR ("The resizing factor was not loaded succesfully. Aborting...\n");
        ros::shutdown();
    }

    // Initializing the image/camera data structures.   
   dataStructuresInitialization ( &LeftCameraImageStruct, &RightCameraImageStruct, &KinectImageStruct );
       
    // GTK library initialization
   gtk_init ( &argc, &argv );

    // Creating a top level window and connecting it to a sygnal.   
    createMainInterfaceWindow ();
   
    // Creating a fixed container, which will hold all the widgets of the GUI.
    createFixedContainer ();
   
    // Creating a GtkGrid widget, which will contain all the images.
    createGtkTable ();
   
    // Attaching the created table to the Container.
    gtk_fixed_put (GTK_FIXED (pGlobalFixedContainer), pGlobalGtkTable, IMAGES_HORIZONTAL_PLACEMENT, IMAGES_VERTIACL_PLACEMENT);
     
   // Subscribing in order to receive images.
   ros::Subscriber subLeft = nh.subscribe<sensor_msgs::Image> ("leftCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[0]));   
    ros::Subscriber subRight = nh.subscribe<sensor_msgs::Image> ("rightCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[1]));
    ros::Subscriber subKinect = nh.subscribe<sensor_msgs::Image> ("kinectCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[2]));


    g_timeout_add(1000 / 100, do_ros, NULL);

    gtk_widget_show_all(globalTopLevelWindow);

    gtk_main();

    ROS_INFO ("The top level window of the application was closed...Exiting the program.\n");

    return 0;
}


Dear Errol,

Again, as before, I am grateful for your professional answer and the time you have spent to write it. I really appreciate your help, and I will try to use your advice.

Best,
Felix.


Top
 Profile  
 
 Post subject: Re: IA__gtk_main_quit: assertion `main_loops != NULL' failed
PostPosted: Sat Jan 28, 2012 12:02 am 
Offline
Familiar Face

Joined: Mon Oct 17, 2011 10:18 am
Posts: 26
errol wrote:
Hi,

This is how I would get around your problem. First it avoids the use of a macro that is really for the implementation of GtkWidget. By using a combination of 'gtk_main()' and 'g_timeout_add()' I have been able to avoid having to busy loop, but still have ROS called at a rate of 100Hz. Also I am not forcing the system to sleep and do no work so you should get a more snappier GUI response.

Code:
gboolean do_ros(gpointer data)
{
    if (ros::ok())
        ros::spinOnce();
    else
        gtk_main_quit();

    return TRUE;
}

int main(int argc, char **argv)
{
   ros::init(argc, argv, "image_listener");
    ros::NodeHandle nh;
   ImageManagmentStruct LeftCameraImageStruct, RightCameraImageStruct, KinectImageStruct;      // Structs for image menagment.     
   
    // Getting the resizing parameter from the launch file.
    if ( !nh.getParam("resizing_factor", globalResizingFactor) )
    {
        ROS_ERROR ("The resizing factor was not loaded succesfully. Aborting...\n");
        ros::shutdown();
    }

    // Initializing the image/camera data structures.   
   dataStructuresInitialization ( &LeftCameraImageStruct, &RightCameraImageStruct, &KinectImageStruct );
       
    // GTK library initialization
   gtk_init ( &argc, &argv );

    // Creating a top level window and connecting it to a sygnal.   
    createMainInterfaceWindow ();
   
    // Creating a fixed container, which will hold all the widgets of the GUI.
    createFixedContainer ();
   
    // Creating a GtkGrid widget, which will contain all the images.
    createGtkTable ();
   
    // Attaching the created table to the Container.
    gtk_fixed_put (GTK_FIXED (pGlobalFixedContainer), pGlobalGtkTable, IMAGES_HORIZONTAL_PLACEMENT, IMAGES_VERTIACL_PLACEMENT);
     
   // Subscribing in order to receive images.
   ros::Subscriber subLeft = nh.subscribe<sensor_msgs::Image> ("leftCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[0]));   
    ros::Subscriber subRight = nh.subscribe<sensor_msgs::Image> ("rightCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[1]));
    ros::Subscriber subKinect = nh.subscribe<sensor_msgs::Image> ("kinectCameraTopic", 10, boost::bind(imageCallback, _1, globalArrayOfImages[2]));


    g_timeout_add(1000 / 100, do_ros, NULL);

    gtk_widget_show_all(globalTopLevelWindow);

    gtk_main();

    ROS_INFO ("The top level window of the application was closed...Exiting the program.\n");

    return 0;
}


Dear Errol,

I have changed my implementation, and everything works perfectly!!!
Thank you for your professionalism and your help :)

Felix.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group