slightly different question (about XSync)
I've been wrestling with this question for about two days now and some have tried to help me but the problem has overcome all suggestions. Can someone please explain to me why this occurs:
I have a struct:
typedef struct {
/* string to display */
char *str;
/* string length, of course */
int slen;
/* position (in percentage) to place string */
/* where top-left-most of window is 0.0,0.0 and */
/* bottom-right-most of window is 1.0,1.0 */
float pos_x;
float pos_y;
} txt_element;
typedef struct {
Pixmap *img;
float pos_x;
float pos_y;
} img_element;
typedef struct {
txt_element t_element;
img_element i_element;
/* command to populate element */
char *cmd;
/* if no command, then a custom function to populate the element */
void (*func) (void *);
/* double var to store a reading (to be displayed by a guage) */
double data_value;
/* will the string change over the course of the apps lifetime */
BOOL constant;
} scr_element;
so then I have a function that populates the 'str' element of txt_element. with the following code:
if ((s_element->t_element.str = malloc(24)) != NULL){
sprintf(s_element->t_element.str, "CPU 0\n %3.2f%%", s_element->data_value);
}
When I sprintf this text:
CPU 0\nLoad: %3.2f%%
it crashes, but with the Load: removed (with a text string small enough) the app stays running. Also, it doesn't crash (when the text is too big) at the sprintf but at a call to XSync that occurs later.
What is the relationship between my struct in memory and XSync that causes this thing to segfault? (ps gdb outputs an error at 'chunk_alloc').
Thanks for any help,
jpbarto
|