can some one please tell me the cause of the error ?

P

pereges

Hello, I am trying to write a library for buildding a kdtree for the
3d mesh. I have uploaded my code on:

http://www.uploading.com/files/LW2EJYPK/code.zip.html

Out of the four modules in the program, kdtree.c is the only one which
is failing at line number 162 , subdivide_kdtree function( I found
this by using some printf statements and checking values). This is the
statement that's failing:

kd->child->ntriangles += 1;

Why is this happening ?? My machine is running low on memory at the
moment, could it because of that ? Can some one else please verify if
this is the problem ?
 
F

Fred

 Hello, I  am trying to write a library for buildding a kdtree for the
3d mesh. I have uploaded my code on:

http://www.uploading.com/files/LW2EJYPK/code.zip.html

Out of the four modules in the program, kdtree.c is the only one which
is failing at line number 162 , subdivide_kdtree function( I found
this by using some printf statements and checking values). This is the
statement that's failing:

kd->child->ntriangles += 1;

Why is this happening ?? My machine is running low on memory at the
moment, could it because of that ? Can some one else please verify if
this is the problem ?


What do you mean by "failing"? How do you *know* it has failed?
Does it not compile?
Does it crash when executed?
Does it add 3 instead of 1?
Is the value of "i" out of range?
Has child been initialized to point to a valid struct?
 
P

pereges

What do you mean by "failing"? How do you *know* it has failed?
Does it not compile?
Does it crash when executed?
Does it add 3 instead of 1?
Is the value of "i" out of range?
Has child been initialized to point to a valid struct?


1. The process abnormally terminates and reutrns a non-zero value.
2. It compiles.
3. No it adds only 1 and increments the value of kd->child-
ntriangles which was initialized to zero.
4. No, it has values 0 and 1.
5. Yes, space has been allocated for child using malloc.
 
H

Harald van Dijk

[context: pereges wrote:]
This is the statement that's failing:

kd->child->ntriangles += 1;


What do you mean by "failing"? How do you *know* it has failed?
[...]
Does it add 3 instead of 1?


The process abnormally terminates and reutrns a non-zero value.
[...]
No it adds only 1 and increments the value of kd->child
->ntriangles which was initialized to zero.


Which is it? Does the process abnormally terminate, or is kd->child
->ntriangles incremented? Or do you mean that the process abnormally
terminates some time after ntriangles is incremented?
 
P

pereges

Which is it? Does the process abnormally terminate, or is kd->child
->ntriangles incremented? Or do you mean that the process abnormally
terminates some time after ntriangles is incremented?


The process abnormally terminates and i think it happens when it
encounters the statement:

kd->child->ntriangles += 1 after a certain number of passes.
 
W

Walter Roberson

Which is it? Does the process abnormally terminate, or is kd->child
->ntriangles incremented? Or do you mean that the process abnormally
terminates some time after ntriangles is incremented?

The process abnormally terminates and i think it happens when it
encounters the statement:
kd->child->ntriangles += 1 after a certain number of passes.


First pass guess is that it happens when i becomes equal to
the length of the kd->child matrix. C matrices are indexed from
0 to (the length minus one)
 
B

Ben Bacarisse

pereges said:
Hello, I am trying to write a library for buildding a kdtree for the
3d mesh. I have uploaded my code on:

http://www.uploading.com/files/LW2EJYPK/code.zip.html

Out of the four modules in the program, kdtree.c is the only one which
is failing at line number 162 , subdivide_kdtree function( I found
this by using some printf statements and checking values). This is the
statement that's failing:

kd->child->ntriangles += 1;

Why is this happening ?? My machine is running low on memory at the
moment, could it because of that ? Can some one else please verify if
this is the problem ?


I see a different problem. valgrind reports an error (illegal write)
at line 178 of kdtree.c. If we look there we see:

kd->child->vertexlist = malloc(sizeof(vector *) * (kd->child->nvertices));
k = 0;
for(j = 0; j < kd->nvertices; j++)
{
if(vertex_inside_box(kd->vertexlist[j], kd->split, axis, i))
kd->child->vertexlist[k] = kd->vertexlist[j]; /* 178 */
k += 1;
}

This looks suspicious. I'd expect the k += 1 to be in the body of the
'if'. Do you really want to leave some of the pointers uninitialised?
The normal idiom for this is to put k++ in index:

kd->child->vertexlist[k++] = kd->vertexlist[j];

and loose the k += 1;.

Also, you allocate space for kd->child->nvertices vector pointers but the
loop runs for kd->nvertices. If I am right about the k++, you need to
be sure that no more than kd->child->nvertices of the kd->nvertices
vertexes pass the condition.
 
K

Keith Thompson

pereges said:
Hello, I am trying to write a library for buildding a kdtree for the
3d mesh. I have uploaded my code on:

http://www.uploading.com/files/LW2EJYPK/code.zip.html

This shows a big green "Download" button. The corresponding URL is
860 characters long. I'm not willing to click it.
Out of the four modules in the program, kdtree.c is the only one which
is failing at line number 162 , subdivide_kdtree function( I found
this by using some printf statements and checking values). This is the
statement that's failing:

kd->child->ntriangles += 1;

Why is this happening ?? My machine is running low on memory at the
moment, could it because of that ? Can some one else please verify if
this is the problem ?


Reduce your code to a small example that exhibits the problem, and
post that. Also, tell us exactly *how* it fails: what output does it
produce, what did you expect, and how do these differ?
 
R

rahul

Hello, I am trying to write a library for buildding a kdtree for the
3d mesh. I have uploaded my code on:

http://www.uploading.com/files/LW2EJYPK/code.zip.html

Out of the four modules in the program, kdtree.c is the only one which
is failing at line number 162 , subdivide_kdtree function( I found
this by using some printf statements and checking values). This is the
statement that's failing:

kd->child->ntriangles += 1;

Why is this happening ?? My machine is running low on memory at the
moment, could it because of that ? Can some one else please verify if
this is the problem ?


It would help if you are specific how the program fails. If under
windows, does it says something like "send error report"?If linux, is
it a segmentation fault? Try running lint on your source code and
valgrind on your executable(if under linux) or equivalent if on some
other problem.

It would help everyone to get to the root of the problem if you
produce the faulty snippet along with the error messages. More people
will help you if they don't have to download and build something.
 
P

pereges

I see a different problem. valgrind reports an error (illegal write)
at line 178 of kdtree.c. If we look there we see:

kd->child->vertexlist = malloc(sizeof(vector *) * (kd->child->nvertices));
k = 0;
for(j = 0; j < kd->nvertices; j++)
{
if(vertex_inside_box(kd->vertexlist[j], kd->split, axis, i))
kd->child->vertexlist[k] = kd->vertexlist[j]; /* 178 */
k += 1;
}

This looks suspicious. I'd expect the k += 1 to be in the body of the
'if'. Do you really want to leave some of the pointers uninitialised?
The normal idiom for this is to put k++ in index:

kd->child->vertexlist[k++] = kd->vertexlist[j];

and loose the k += 1;.


thanks, this worked.

Also, you allocate space for kd->child->nvertices vector pointers but the
loop runs for kd->nvertices. If I am right about the k++, you need to
be sure that no more than kd->child->nvertices of the kd->nvertices
vertexes pass the condition.


The idea is distribute the vertices of the parent node (pointed to by
kd) among the child nodes (pointed to by kd->child where i is 0 or
1). Yes, I must check that k == kd->child->nvertices.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top