code crash after 25-30 min only!
- From: Eric Wajnberg <eric wajnberg sophia inra fr>
- To: gtk-app-devel-list gnome org
- Subject: code crash after 25-30 min only!
- Date: Tue, 16 Apr 2013 13:58:37 +0200
Hi there,
I just remain unable to debug this code. Actually, it runs very well but
crashes after 30-35 minutes only.
This is a "stopwatch-type" app. However, I actually need to refresh
things on a continuous basis. Hence, a g_timeout_add_seconds() is
**not** what I need. The idea of a stopwatch is just a way for me to
learn and practice.
The code that I have is more or less this one:
#include <stdlib.h>
#include <gtk/gtk.h>
#include <strings.h>
int flag_depart=1;
char format_sortie[100];
typedef struct
{
GtkWidget *widget1;
GTimer *widget2;
} MyStruct; /* a struct to pass several arguments to an callback */
int main(int argc, char **argv)
{
/* declaration of widgets */
[...]
GtkWidget *pLabel; /* a label */
GTimer *timer; /* a timer */
gchar* sUtf8; /* to format a char string */
[...]
MyStruct struct_tempo; /* a struct to pass several arguments to an
callback */
[...]
gboolean OnExpose(GtkWidget *pWidget, GdkEvent *event, gpointer
pData); /* function callback expose-event */
[...]
/* creation of the label */
pLabel=gtk_label_new(NULL);
(void)sprintf(format_sortie, "<span font_desc=\"25\"><b>00 : 00 :
00</b></span>");
sUtf8 = g_locale_to_utf8(format_sortie, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pLabel), sUtf8);
g_free(sUtf8);
/* we put the label in the struct */
struct_tempo.widget1=pLabel;
/* creation of the timer */
timer=g_timer_new();
/* we put the timer in the struct */
struct_tempo.widget2=timer;
/* Connexion of signals */
g_signal_connect(G_OBJECT(pWindow), "expose-event",
G_CALLBACK(OnExpose), (gpointer )&struct_tempo);
[...]
return EXIT_SUCCESS;
}
gboolean OnExpose(GtkWidget *pWidget, GdkEvent *event, gpointer pData)
{
/* updating the label */
char tempo[1000],h[3],m[3],s[3];
int heures=0, minutes=0;
GTimeSpan secondes=0;
gchar* sUtf8;
MyStruct *struct_tempo2;
struct_tempo2= (MyStruct *)pData;
float convertir(GTimeSpan *secondes, int *minutes, int *heures);
if (flag_depart)
{
secondes=(GTimeSpan)g_timer_elapsed(struct_tempo2->widget2, NULL);
convertir(&secondes, &minutes, &heures);
if (secondes>9)
(void)sprintf(s, "%d",secondes);
else
(void)sprintf(s, "0%d",secondes);
if (minutes>9)
(void)sprintf(m, "%d",minutes);
else
(void)sprintf(m, "0%d",minutes);
if (heures>9)
(void)sprintf(h, "%d",heures);
else
(void)sprintf(h, "0%d",heures);
(void)sprintf(tempo, "<span font_desc=\"25\"><b>%s : %s :
%s</b></span>",h, m, s);
sUtf8 = g_locale_to_utf8(tempo, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(struct_tempo2->widget1), tempo);
}
g_free(sUtf8);
return FALSE;
}
float convertir(GTimeSpan *secondes, int *minutes, int * heures)
{
/* convert seconds into hours, minuts and seconds */
while (*secondes>59)
{
*minutes=*minutes+1;
*secondes=*secondes-60;
}
while (*minutes>59)
{
*heures=*heures+1;
*minutes=*minutes-60;
}
}
This codes works well but crashes avec about 30-35 minutes. I code in
Windows 7 with CodeBlock. I've tried to use a debugger, but I get a:
Segmentation fault.
In ntdll!LdrWx86FormatVirtualImage () (C:\Windows\system32\ntdll.dll)
as soon as the gtk_main() is launched. I have really no idea about how I
can solve this now.
Any help will be welcomed!!
Thanks in advance for this.
Cheers, Eric.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Eric Wajnberg
Associated Professor at the
University of Montreal (Quebec, Canada)
I.N.R.A.
400 Route des Chappes, BP 167,
06903 Sophia Antipolis Cedex, France
Tel: (33-0) 4.92.38.64.47
Fax: (33-0) 4.92.38.65.57
e-mail: wajnberg sophia inra fr
Web page: http://www.sophia.inra.fr/perso/wajnberg/
Editor-in-Chief of BioControl, Published by Springer.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]