F
Fabian Wauthier
Hi List,
I'm not sure if this is the appropriate list for this, but perhaps
someone has got some pointers or ideas...
The assert fails at some point. However, everything seems to work fine
once I add a line:
printf("");
to my code. I discovered this when trying to print our info-messages
to help me find the bug. To be a bit more specific, this is the code:
a->x, a->y, (a->v)->x and (a->v)->y are floats,
Width = 80, Height = 24 are ints.
--cut--
a->x += (a->v)->x;
a->y += (a->v)->y;
/* Check if atom is off one of the egdes; if so, continually
adjust the corresponding coordinate (mirror point along the
corresponding edge) until it's within bounds, inverting the
vector each time */
/**** Help with this line ****/
printf("");
/*****************************/
/* Check if x coord is off screen; (int) x < 0 || (int) x >= Width */
while(((int) a->x < 0) || ((int) a->x >= Width)) {
/* Check if (int) x < 0 */
if((int) a->x < 0) {
a->x = fabsf(a->x); /* Mirror along edge */
(a->v)->x *= -1; /* Invert vector */
}
/* Check if (int) x >= Width */
if((int) a->x >= Width) {
a->x = 2 * (Width - 1) - a->x; /* Mirror along edge */
(a->v)->x *= -1; /* Invert vector */
}
}
/* Assert that everything is OK now; This fails at some point */
assert(((int) a->x >= 0) && ((int) a->x < Width));
--cut--
Why do the numbers slip past the test at the head of the while, but
then trigger the assert that follows? Why does printf(""); change
all this? Perhaps this points to a problem elsewhere? I don't use any
threading.
I hope this mail wasn't to verbose, any pointers and comments appreceated.
Fabian
I'm not sure if this is the appropriate list for this, but perhaps
someone has got some pointers or ideas...
The assert fails at some point. However, everything seems to work fine
once I add a line:
printf("");
to my code. I discovered this when trying to print our info-messages
to help me find the bug. To be a bit more specific, this is the code:
a->x, a->y, (a->v)->x and (a->v)->y are floats,
Width = 80, Height = 24 are ints.
--cut--
a->x += (a->v)->x;
a->y += (a->v)->y;
/* Check if atom is off one of the egdes; if so, continually
adjust the corresponding coordinate (mirror point along the
corresponding edge) until it's within bounds, inverting the
vector each time */
/**** Help with this line ****/
printf("");
/*****************************/
/* Check if x coord is off screen; (int) x < 0 || (int) x >= Width */
while(((int) a->x < 0) || ((int) a->x >= Width)) {
/* Check if (int) x < 0 */
if((int) a->x < 0) {
a->x = fabsf(a->x); /* Mirror along edge */
(a->v)->x *= -1; /* Invert vector */
}
/* Check if (int) x >= Width */
if((int) a->x >= Width) {
a->x = 2 * (Width - 1) - a->x; /* Mirror along edge */
(a->v)->x *= -1; /* Invert vector */
}
}
/* Assert that everything is OK now; This fails at some point */
assert(((int) a->x >= 0) && ((int) a->x < Width));
--cut--
Why do the numbers slip past the test at the head of the while, but
then trigger the assert that follows? Why does printf(""); change
all this? Perhaps this points to a problem elsewhere? I don't use any
threading.
I hope this mail wasn't to verbose, any pointers and comments appreceated.
Fabian