Re: weird problem
- From: Alef.Veld@xxxxxxxxx
- Date: 24 Jan 2007 12:02:31 -0800
On Jan 24, 7:51 pm, j...@xxxxxxxxxxx (Jens Thoms Toerring) wrote:
}obviously must be using. 'GLvoid' is probably only a fanvy name for
assign_coordinate looks like this:
GLvoid assign_coordinate(objects *tmp)What's 'objects' for a kind of type? You don't show the typedef you
'void', isn't it?
GL is a prefix for using variables with GLUT. Yes they are the same.
objects is a typedef for a struct like:
typedef struct objects {
char *x;
char *y;
char *z;
} objects;
{
objects *search = o_head;What's 'o_head'?
o_head is a objects pointer pointing to the first node in the linked
list i'm using.
if ( ! tmp->prev && object_count == 1 )Where is 'object_count' defined and what's its type?
object_count is a global (declared extern in header and intialized in
other function). type is int.
I know this, i will just remove the sizeof float and put the amount of
srand((unsigned int)time(NULL));
/* Assign coordinate planes */need when printing a float or double value out in ASCII good for? This
if ((tmp->x = malloc(sizeof(float) + 7)) == NULL) {What is using "sizeof(float)" in the calculation of how much memory you
doesn't make any sense and is probably dangerous since sizeof(float)
can differ between different machines while the ASCII string you want
to output stays the same.
bytes in there i need. I still need to change this, didn't get around
to it yet.
fprintf(stderr, "assign_coordinate: Could not allocate memory for x plane\n");it fails to obtain as much memory as requested. perror() is meant to
perror("malloc");Using perror() here is useless since malloc() doesn't set set errno if
print out a human-readable string for what errno is set to. And if
there's nothing that woul have set errno what it prints out is com-
pletely bogus.
Hmm, yes kind of a shame malloc doesn;t use errno. I use perror because
i want to do consistent error reporting so i use it with every error,
if errno is used or not.
exit(1);the string 'tmp->x' you just allocated before? And where are 'grid_start'
}
snprintf(o_tail->x, sizeof(float) + 7, "%.0f",
((grid_size - grid_start) * rand()) / RAND_MAX +
grid_start);Where is 'o_tail' defined? Are you sure you don't intend to write into
and 'grid_size' defined what what type do the have? Are they floats or
doubles or something else?
o_tail is a global pointing to the last node in the linked list. I'm
not sure you mean by 'i don't intend to write into
the string tmp->x you just allocated before'. I want to write into the
string, i just freed them remember? grid_start
and grid_size are floats. they are set in the beginning of the program
to -10 and grid_size is calculated dynamically, depending on how many
objects there are.
if ((tmp->y = malloc(sizeof(float) + 7)) == NULL) {
fprintf(stderr,"assign_coordinate: Could not allocate memory "
"for y plane\n");
perror("malloc");
exit(1);
}
snprintf(o_tail->y, sizeof(float) + 7, "%.0f", grid_object );Where's the definition of grid_object?
float, value is 2.0
collisions is int and defined as a global (and declared extern) . It is
if ((tmp->z = malloc(sizeof(float) + 7)) == NULL ) {
fprintf(stderr,"assign_coordinate: Could not allocate "
memory for z plane\n");
perror("malloc");
exit(1);
}
snprintf(o_tail->z, sizeof(float) + 7,"%.0f",
((grid_size - grid_start) * rand()) / RAND_MAX +
grid_start );
/* Check for possible collision */integer counter, but you seem to compare it to some float or double value,
while (search != NULL) {
if (collisions > 0 &&
collisions ==
((grid_size - grid_start) * (grid_size - grid_start))) {Where is 'collisions' defined and what type does it have? Looks like an
which, if these assumptions should be true, is rather dubious to say the
least. But since I have no idea what it's meant to test I can't make any
suggestions on how to correct it.
only reset when the grid_size is increased, otherwise it is incremented
for every collision it matches.
fprintf(stderr,"assign_coordinate: Sector collisions "errno.
"100%%.Collisions: %d - Objects: %d - Grid size: "
"%.0f [%.0f^2 sectors]\n",
collisions, object_count,
(grid_size - grid_start) * (grid_size - grid_start),
grid_size - grid_start);
perror("assign_coordinate");Again, using perror() is useless if nothing happened that would have set
I know :-)
Eek :-P
exit(1);
}
if (tmp != search &&
!strcmp(tmp->x, search->x) &&
!strcmp(tmp->y, search->y) &&
!strcmp(tmp->z, search->z))
{
fprintf(stderr,"%s %s %s %s - %s %s %s %s\n",
tmp->hostname, tmp->x, tmp->y, tmp->z,
search->hostname, search->x, search->y, search->z);
collisions++;
free(tmp->x);
free(tmp->y);
free(tmp->z);
assign_coordinate(tmp);
}
search=search->next;memory, while printing out 'o_tail->x' probably won't tell you anything
}
}
I have no snprintf check for error in there yet, but i checked with
printf statements if it
assigned properly, and it did.What did you printf() out? E.g. 'tmp->x' would point to uninitialized
about 'tmp->x' (unless you're hinding some code where you assign 'tmp'
to 'o_tail').
But, when going in the search loop,
apparently tmp->x y and z and search->x,y,z are not valid anymore
because they are both NULL so it seems. That's
why i get 100% collisions all the time, or so i gather. I don't
understand, because i'm
excluding myself (and thus my freed x,y,z) and i did not yet free
future nodes x,y,z in the list.Sorry, but nothing you write here makes much sense.
How do you deter-
mine that tmp->x or tmp->y or tmp->z are NULL? And since you don't
show what 'search' is and how it got set up there's no way someone
could figure out what's going wrong.
search is just a tmp pointer set to the 'head' of the list. I don't
understand
why i would want to test x y and z for NULL. I free them before i dive
into
assign_coordinate, and allocate them right back after. So they are
always
allocated. The other pointers search encounters, are not yet freed and
still
valid.
If you post code it's best if
it's a complete, compilable program. If that is really not possible
take care to include definition of the variables being used and at
least give a hint what they are set to. And only post the code you
were actually using, not something you copied manually.
I'm using everything i posted, albeit somewhat simplified posted maybe.
I hope this clear things up, if not, i will try and post longer
listings of code with the variables
in there.
.
- Follow-Ups:
- Re: weird problem
- From: Jens Thoms Toerring
- Re: weird problem
- References:
- weird problem
- From: atv
- Re: weird problem
- From: Jens Thoms Toerring
- weird problem
- Prev by Date: Re: which hash table - chained or open-addressed? - TPA
- Next by Date: Re: digits to words
- Previous by thread: Re: weird problem
- Next by thread: Re: weird problem
- Index(es):
Relevant Pages
|