Re: Timer start registration breaks the gtk_main()
Thank you for the help, guys. Everything works as expected. Now to check the data validity -Original Message- From: Ingo Krabbe ikrabbe@gmail.com Sent: Mar 27, 2011 3:33 AM To: gtk-list@gnome.org Subject: Re: Timer start registration breaks the gtk_main() On Sat, Mar 26, 2011 at 11:48:38PM -0700, iko...@earthlink.net wrote: Lex, -Original Message- From: Lex Trotman ele...@gmail.com Sent: Mar 26, 2011 10:47 PM To: iko...@earthlink.net Cc: gtk-list gtk-list@gnome.org Subject: Re: Timer start registration breaks the gtk_main() It is not automagically passed a pointer to an instance of the object (no this) so it will only work if the function does not access any instance members. Which means that every member of the class that will be used by this function should be static. But this is not good. Not if you want more than one instance :-) Which is not the case here. ;-) To make that finally clear, thats why the signal functions pass a data pointer. So to use C++ you can always either pass the object into the static function: class CFrame { static gboolean ReadData(CFrame* me); }; /* ... */ g_timeout_add_seconds(1,(GSourceFunc)CFrame::ReadData,frame); or I would prefer to leave the C++ alone and write a small wrapper frame_ReadData(CFrame* f) { return f-ReadData(); } /* ... */ g_timeout_add_seconds(1,(GSourceFunc)frame_ReadData,frame); ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Lex, -Original Message- From: Lex Trotman ele...@gmail.com Sent: Mar 26, 2011 10:47 PM To: iko...@earthlink.net Cc: gtk-list gtk-list@gnome.org Subject: Re: Timer start registration breaks the gtk_main() It is not automagically passed a pointer to an instance of the object (no this) so it will only work if the function does not access any instance members. Which means that every member of the class that will be used by this function should be static. But this is not good. Not if you want more than one instance :-) Which is not the case here. ;-) If you are writing in C++ why don't you use gtkmm, the C++ binding which has the ability to call bound member functions? Originally I wrote my program with wxWidgets, but it was repeatedly crashing without even initializing. But it looks like I will need to do some more work. Well, wxwidgets works too but it is more than just a binding, but gtkmm is the official C++ binding for GTK. Ok, I will look into this. But right now, I need to do the release as it's already late. Thank you all for the help. I will make the function static and see if there is a chance to do that with gtkmm later. Cheers Lex Thank you. Cheers Lex ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Hi iko...@earthlink.net, On Sat, 26 Mar 2011 20:45:53 -0700 (GMT-07:00) you wrote: Yes. You are casting the _RESULT_ of a _CALL_ to ReadData into a GSourceFunc, but ReadData returns void. This produces utterly random results. Yes, I believe I made a mistake here. I was not in front of my developmental machine, so... I think the ReadData() is returning gboolean. Perhaps, but a gboolean is most definitely not the same as a GSourceFunc. So I shall reiterate: g_timer_add_seconds( 1, (GSourceFunc) frame-ReadData(), NULL ); ^^ You are casting the _RESULT_ of a _CALL_ to ReadData into a GSourceFunc, but ReadData returns bool. This produces guaranteed illegal results. The second argument of g_timeout_add_seconds is a function pointer, and requires that you pass it a simple C function reference _without_ the call syntax. Unless you're now going to say that you'd misremembered that too, and the actual code doesn't have the () after the frame-ReadData in the line I re-quoted. It would really help us to help you if you had posted your actual code rather than a misremembered vague approximation. Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
On Sat, Mar 26, 2011 at 11:48:38PM -0700, iko...@earthlink.net wrote: Lex, -Original Message- From: Lex Trotman ele...@gmail.com Sent: Mar 26, 2011 10:47 PM To: iko...@earthlink.net Cc: gtk-list gtk-list@gnome.org Subject: Re: Timer start registration breaks the gtk_main() It is not automagically passed a pointer to an instance of the object (no this) so it will only work if the function does not access any instance members. Which means that every member of the class that will be used by this function should be static. But this is not good. Not if you want more than one instance :-) Which is not the case here. ;-) To make that finally clear, thats why the signal functions pass a data pointer. So to use C++ you can always either pass the object into the static function: class CFrame { static gboolean ReadData(CFrame* me); }; /* ... */ g_timeout_add_seconds(1,(GSourceFunc)CFrame::ReadData,frame); or I would prefer to leave the C++ alone and write a small wrapper frame_ReadData(CFrame* f) { return f-ReadData(); } /* ... */ g_timeout_add_seconds(1,(GSourceFunc)frame_ReadData,frame); ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Ingo, -Original Message- From: Ingo Krabbe ikrabbe@gmail.com Sent: Mar 27, 2011 12:33 AM To: gtk-list@gnome.org Subject: Re: Timer start registration breaks the gtk_main() On Sat, Mar 26, 2011 at 11:48:38PM -0700, iko...@earthlink.net wrote: Lex, -Original Message- From: Lex Trotman ele...@gmail.com Sent: Mar 26, 2011 10:47 PM To: iko...@earthlink.net Cc: gtk-list gtk-list@gnome.org Subject: Re: Timer start registration breaks the gtk_main() It is not automagically passed a pointer to an instance of the object (no this) so it will only work if the function does not access any instance members. Which means that every member of the class that will be used by this function should be static. But this is not good. Not if you want more than one instance :-) Which is not the case here. ;-) To make that finally clear, thats why the signal functions pass a data pointer. So to use C++ you can always either pass the object into the static function: class CFrame { static gboolean ReadData(CFrame* me); }; /* ... */ g_timeout_add_seconds(1,(GSourceFunc)CFrame::ReadData,frame); or I would prefer to leave the C++ alone and write a small wrapper frame_ReadData(CFrame* f) { return f-ReadData(); } /* ... */ g_timeout_add_seconds(1,(GSourceFunc)frame_ReadData,frame); Shouldn't it be: static frame_ReadData(CFrame *f) { return f-ReadData(); } ? Thank you. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
replied too fast... - Forwarded message from Ingo Krabbe ikrabbe@gmail.com - static frame_ReadData(CFrame *f) { return f-ReadData(); } Actually and fully you will need static gboolean frame_ReadData(CFrame* f) { return f-ReadData(); } Note that frame_ReadData is a C function, so that static means something different than in the C++ class context. Actually nothing speaks against using an extern function, though it might make not much sense to export such a simple, locally used function. - End forwarded message - ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
On Sat, 26 Mar 2011 20:27:04 -0700 (GMT-07:00) iko...@earthlink.net wrote: Yes, ReadData() is a non-static class member function. Illegal casts to avoid compilation failure has, as you can tell, not saved you here. So in order to fix it, I need to use 'static' in front of 'void ReadData()'? You should most properly use a plain function with C linkage as the callback. If you want to access instance (non-static) data you need to pass in an instance pointer; and if it needs to access private data it should be made a friend. Basically what you want is something like this: // *** header file *** extern C gboolean cframe_read_data(void* data); class CFrame { ... public: ... gboolean ReadData(); }; // *** implementation file *** gboolean cframe_read_data(void* data) { return static_castCFrame*(data)-ReadData(); } int main() { ... CFrame* cf = new CFrame; g_timer_add_seconds( 1, cframe_read_data, cf); ... } This is all very basic C/C++ Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Timer start registration breaks the gtk_main()
Hi, ALL, Is it possible for the timer to cause gtk_main() to crash? How do I debug/fix it? Thank you. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Hi iko...@earthlink.net, On Sat, 26 Mar 2011 01:54:31 -0700 (GMT-07:00) you wrote: Hi, ALL, Is it possible for the timer to cause gtk_main() to crash? It's possible for anything to become the point where your program crashes if you are sufficiently badly abusing it. Why do you pick on the timer as your suspect? How do I debug/fix it? There are many answers to this, all outside the scope of this mailing list. How do you normally approach debugging? Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Hi, Robert, -Original Message- From: Robert Pearce r...@bdt-home.demon.co.uk Sent: Mar 26, 2011 2:19 AM To: gtk-list@gnome.org Cc: iko...@earthlink.net Subject: Re: Timer start registration breaks the gtk_main() Hi iko...@earthlink.net, On Sat, 26 Mar 2011 01:54:31 -0700 (GMT-07:00) you wrote: Hi, ALL, Is it possible for the timer to cause gtk_main() to crash? It's possible for anything to become the point where your program crashes if you are sufficiently badly abusing it. Why do you pick on the timer as your suspect? If I comment out the call to g_timer_add_seconds() it does not crash. Here is what I do: int main() { CFrame *frame = new CFrame(); result = frame-OpenPort(); if( !result ) return 1; else { g_timer_add_seconds( 1, (GSourceFunc) frame-ReadData(), NULL ); gtk_widget_show( window ); frame-ReadData(); gtk_main(); } } in frame.h: class CFrame { void ReadData(); } Do you see any problems with that? Basically followed example from http://zetcode.com/tutorials/gtktutorial/gtkevents/. How do I debug/fix it? There are many answers to this, all outside the scope of this mailing list. How do you normally approach debugging? Just run the program under gdb and get the point of crash. Check all the variables at runtime under gdb. Then study the code and see what the problem is. Thank you. Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Hello. int main() { CFrame *frame = new CFrame(); result = frame-OpenPort(); if( !result ) return 1; else { g_timer_add_seconds( 1, (GSourceFunc) frame-ReadData(), NULL ); gtk_widget_show( window ); frame-ReadData(); gtk_main(); } } Where is your gtk_init() call? Cheers, Tadej -- Tadej Borovšak tadeboro.blogspot.com tadeb...@gmail.com tadej.borov...@gmail.com ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Il giorno Sat, 26 Mar 2011 11:38:27 -0700 (GMT-07:00) iko...@earthlink.net ha scritto: Hi, Robert, -Original Message- From: Robert Pearce r...@bdt-home.demon.co.uk Sent: Mar 26, 2011 2:19 AM To: gtk-list@gnome.org Cc: iko...@earthlink.net Subject: Re: Timer start registration breaks the gtk_main() Hi iko...@earthlink.net, On Sat, 26 Mar 2011 01:54:31 -0700 (GMT-07:00) you wrote: Hi, ALL, Is it possible for the timer to cause gtk_main() to crash? It's possible for anything to become the point where your program crashes if you are sufficiently badly abusing it. Why do you pick on the timer as your suspect? If I comment out the call to g_timer_add_seconds() it does not crash. Here is what I do: int main() { CFrame *frame = new CFrame(); result = frame-OpenPort(); if( !result ) return 1; else { g_timer_add_seconds( 1, (GSourceFunc) frame-ReadData(), NULL ); gtk_widget_show( window ); frame-ReadData(); gtk_main(); } } in frame.h: class CFrame { void ReadData(); } Do you see any problems with that? Basically followed example from http://zetcode.com/tutorials/gtktutorial/gtkevents/. ReadData() is not a good old C function, but a C++ method, carrying around a pointer to the CFrame instance. You should make ReadData() static or use more advanced tecniques, such as libsigc++ [1]. Ciao. -- Nicola [1] http://libsigc.sourceforge.net/ How do I debug/fix it? There are many answers to this, all outside the scope of this mailing list. How do you normally approach debugging? Just run the program under gdb and get the point of crash. Check all the variables at runtime under gdb. Then study the code and see what the problem is. Thank you. Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
On Sat, 26 Mar 2011 11:38:27 -0700 (GMT-07:00) iko...@earthlink.net wrote: If I comment out the call to g_timer_add_seconds() it does not crash. Here is what I do: int main() { CFrame *frame = new CFrame(); result = frame-OpenPort(); if( !result ) return 1; else { g_timer_add_seconds( 1, (GSourceFunc) frame-ReadData(), NULL ); gtk_widget_show( window ); frame-ReadData(); gtk_main(); } } in frame.h: class CFrame { void ReadData(); } Do you see any problems with that? Yes, ReadData() is a non-static class member function. Illegal casts to avoid compilation failure has, as you can tell, not saved you here. Since you don't provide the implementation of any of the other calls you are making, it is possible (maybe likely) that there are a number of other errors in your code. Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
On Sat, 26 Mar 2011 21:10:30 +0100 Nicola Fontana n...@entidi.it wrote: ReadData() is not a good old C function, but a C++ method, carrying around a pointer to the CFrame instance. You should make ReadData() static [ ...] That is a less grievous error than the original code (it will work on gcc), but a potential error none the less. GTK+ callbacks should have C linkage specification whereas static member functions have C++ linkage. gcc will be OK. Some compilers (in particular some intel compilers) will not: it won't work with any compiler which uses a different calling convention for static member functions than functions with C linkage. Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Hi iko...@earthlink.net, On Sat, 26 Mar 2011 11:38:27 -0700 (GMT-07:00) you wrote: Hi, Robert, Here is what I do: int main() { CFrame *frame = new CFrame(); result = frame-OpenPort(); if( !result ) return 1; else { g_timer_add_seconds( 1, (GSourceFunc) frame-ReadData(), NULL ); ^ ^^ gtk_widget_show( window ); frame-ReadData(); gtk_main(); } } in frame.h: class CFrame { void ReadData(); } Do you see any problems with that? Yes. You are casting the _RESULT_ of a _CALL_ to ReadData into a GSourceFunc, but ReadData returns void. This produces utterly random results. The second argument of g_timeout_add_seconds is a function pointer, and requires that you pass it a simple C function reference _without_ the call syntax. Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Tadej, -Original Message- From: Tadej Borovšak tadeb...@gmail.com Sent: Mar 26, 2011 12:54 PM To: gtk-list@gnome.org Subject: Re: Timer start registration breaks the gtk_main() Hello. int main() { CFrame *frame = new CFrame(); result = frame-OpenPort(); if( !result ) return 1; else { g_timer_add_seconds( 1, (GSourceFunc) frame-ReadData(), NULL ); gtk_widget_show( window ); frame-ReadData(); gtk_main(); } } Where is your gtk_init() call? I was too lazy to type it in. I was not at my computer to do copypaste. Cheers, Tadej -- Tadej Borovšak tadeboro.blogspot.com tadeb...@gmail.com tadej.borov...@gmail.com ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Nicola, -Original Message- From: Nicola Fontana n...@entidi.it Sent: Mar 26, 2011 1:10 PM To: iko...@earthlink.net Cc: Robert Pearce r...@bdt-home.demon.co.uk, gtk-list@gnome.org Subject: Re: Timer start registration breaks the gtk_main() Il giorno Sat, 26 Mar 2011 11:38:27 -0700 (GMT-07:00) iko...@earthlink.net ha scritto: Hi, Robert, -Original Message- From: Robert Pearce r...@bdt-home.demon.co.uk Sent: Mar 26, 2011 2:19 AM To: gtk-list@gnome.org Cc: iko...@earthlink.net Subject: Re: Timer start registration breaks the gtk_main() Hi iko...@earthlink.net, On Sat, 26 Mar 2011 01:54:31 -0700 (GMT-07:00) you wrote: Hi, ALL, Is it possible for the timer to cause gtk_main() to crash? It's possible for anything to become the point where your program crashes if you are sufficiently badly abusing it. Why do you pick on the timer as your suspect? If I comment out the call to g_timer_add_seconds() it does not crash. Here is what I do: int main() { CFrame *frame = new CFrame(); result = frame-OpenPort(); if( !result ) return 1; else { g_timer_add_seconds( 1, (GSourceFunc) frame-ReadData(), NULL ); gtk_widget_show( window ); frame-ReadData(); gtk_main(); } } in frame.h: class CFrame { void ReadData(); } Do you see any problems with that? Basically followed example from http://zetcode.com/tutorials/gtktutorial/gtkevents/. ReadData() is not a good old C function, but a C++ method, carrying around a pointer to the CFrame instance. You should make ReadData() static or use more advanced tecniques, such as libsigc++ [1]. So all I need is to do: class CFrame { static void ReadData(); } ? Thank you. Ciao. -- Nicola [1] http://libsigc.sourceforge.net/ How do I debug/fix it? There are many answers to this, all outside the scope of this mailing list. How do you normally approach debugging? Just run the program under gdb and get the point of crash. Check all the variables at runtime under gdb. Then study the code and see what the problem is. Thank you. Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Chris, -Original Message- From: Chris Vine ch...@cvine.freeserve.co.uk Sent: Mar 26, 2011 2:05 PM To: iko...@earthlink.net Cc: gtk-list@gnome.org Subject: Re: Timer start registration breaks the gtk_main() On Sat, 26 Mar 2011 11:38:27 -0700 (GMT-07:00) iko...@earthlink.net wrote: If I comment out the call to g_timer_add_seconds() it does not crash. Here is what I do: int main() { CFrame *frame = new CFrame(); result = frame-OpenPort(); if( !result ) return 1; else { g_timer_add_seconds( 1, (GSourceFunc) frame-ReadData(), NULL ); gtk_widget_show( window ); frame-ReadData(); gtk_main(); } } in frame.h: class CFrame { void ReadData(); } Do you see any problems with that? Yes, ReadData() is a non-static class member function. Illegal casts to avoid compilation failure has, as you can tell, not saved you here. So in order to fix it, I need to use 'static' in front of 'void ReadData()'? Thank you. Since you don't provide the implementation of any of the other calls you are making, it is possible (maybe likely) that there are a number of other errors in your code. Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
ReadData() is not a good old C function, but a C++ method, carrying around a pointer to the CFrame instance. You should make ReadData() static or use more advanced tecniques, such as libsigc++ [1]. So all I need is to do: class CFrame { static void ReadData(); } ? Thank you. Do you understand what static member function means? It is not automagically passed a pointer to an instance of the object (no this) so it will only work if the function does not access any instance members. If you are writing in C++ why don't you use gtkmm, the C++ binding which has the ability to call bound member functions? Cheers Lex ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Robert, -Original Message- From: Robert Pearce r...@bdt-home.demon.co.uk Sent: Mar 26, 2011 3:14 PM To: iko...@earthlink.net Cc: gtk-list@gnome.org Subject: Re: Timer start registration breaks the gtk_main() Hi iko...@earthlink.net, On Sat, 26 Mar 2011 11:38:27 -0700 (GMT-07:00) you wrote: Hi, Robert, Here is what I do: int main() { CFrame *frame = new CFrame(); result = frame-OpenPort(); if( !result ) return 1; else { g_timer_add_seconds( 1, (GSourceFunc) frame-ReadData(), NULL ); ^ ^^ gtk_widget_show( window ); frame-ReadData(); gtk_main(); } } in frame.h: class CFrame { void ReadData(); } Do you see any problems with that? Yes. You are casting the _RESULT_ of a _CALL_ to ReadData into a GSourceFunc, but ReadData returns void. This produces utterly random results. Yes, I believe I made a mistake here. I was not in front of my developmental machine, so... I think the ReadData() is returning gboolean. Thank you. The second argument of g_timeout_add_seconds is a function pointer, and requires that you pass it a simple C function reference _without_ the call syntax. Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
Lex, -Original Message- From: Lex Trotman ele...@gmail.com Sent: Mar 26, 2011 8:41 PM To: iko...@earthlink.net Cc: gtk-list gtk-list@gnome.org Subject: Re: Timer start registration breaks the gtk_main() ReadData() is not a good old C function, but a C++ method, carrying around a pointer to the CFrame instance. You should make ReadData() static or use more advanced tecniques, such as libsigc++ [1]. So all I need is to do: class CFrame { static void ReadData(); } ? Thank you. Do you understand what static member function means? It is not automagically passed a pointer to an instance of the object (no this) so it will only work if the function does not access any instance members. Which means that every member of the class that will be used by this function should be static. But this is not good. If you are writing in C++ why don't you use gtkmm, the C++ binding which has the ability to call bound member functions? Originally I wrote my program with wxWidgets, but it was repeatedly crashing without even initializing. But it looks like I will need to do some more work. Thank you. Cheers Lex ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Timer start registration breaks the gtk_main()
It is not automagically passed a pointer to an instance of the object (no this) so it will only work if the function does not access any instance members. Which means that every member of the class that will be used by this function should be static. But this is not good. Not if you want more than one instance :-) If you are writing in C++ why don't you use gtkmm, the C++ binding which has the ability to call bound member functions? Originally I wrote my program with wxWidgets, but it was repeatedly crashing without even initializing. But it looks like I will need to do some more work. Well, wxwidgets works too but it is more than just a binding, but gtkmm is the official C++ binding for GTK. Cheers Lex Thank you. Cheers Lex ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list