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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pereges

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

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



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

    kd->child[i]->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 ?
  • Fred

    #2
    Re: can some one please tell me the cause of the error ?

    On Jun 25, 11:05 am, pereges <Brol...@gmail. comwrote:
     Hello, I  am trying to write a library for buildding a kdtree for the
    3d mesh. I have uploaded my code on:
    >

    >
    Out of the four modules in the program, kdtree.c is the only one which
    is failing at line number 162 , subdivide_kdtre e function( I found
    this by using some printf statements and checking values). This is the
    statement that's failing:
    >
    kd->child[i]->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[i] been initialized to point to a valid struct?


    --
    Fred Kleinschmidt

    Comment

    • pereges

      #3
      Re: can some one please tell me the cause of the error ?

      On Jun 26, 12:31 am, Fred <fred.l.kleinsc hm...@boeing.co mwrote:
      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[i] 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[i]-
      >ntriangles which was initialized to zero.
      4. No, it has values 0 and 1.
      5. Yes, space has been allocated for child[i] using malloc.

      Comment

      • Harald van =?UTF-8?b?RMSzaw==?=

        #4
        Re: can some one please tell me the cause of the error ?

        On Wed, 25 Jun 2008 12:52:03 -0700, pereges wrote:
        On Jun 26, 12:31 am, Fred <fred.l.kleinsc hm...@boeing.co mwrote:
        >>[context: pereges wrote:]
        >>This is the statement that's failing:
        >>>
        >>kd->child[i]->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[i]
        ->ntriangles which was initialized to zero.
        Which is it? Does the process abnormally terminate, or is kd->child[i]
        ->ntriangles incremented? Or do you mean that the process abnormally
        terminates some time after ntriangles is incremented?

        Comment

        • pereges

          #5
          Re: can some one please tell me the cause of the error ?

          On Jun 26, 1:11 am, Harald van D©¦k <true...@gmail. comwrote:
          Which is it? Does the process abnormally terminate, or is kd->child[i]
          ->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[i]->ntriangles += 1 after a certain number of passes.

          Comment

          • Walter Roberson

            #6
            Re: can some one please tell me the cause of the error ?

            In article <e3cffb92-a9f9-402b-b053-40cd2293802d@g1 6g2000pri.googl egroups.com>,
            pereges <Broli00@gmail. comwrote:
            >On Jun 26, 1:11 am, Harald van D=A9=A6k <true...@gmail. comwrote:
            >Which is it? Does the process abnormally terminate, or is kd->child[i]
            >->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[i]->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)
            --
            "The study of error is not only in the highest degree
            prophylatic, but it serves as a stimulating introduction to the
            study of truth." -- Walter Lipmann

            Comment

            • Ben Bacarisse

              #7
              Re: can some one please tell me the cause of the error ?

              pereges <Broli00@gmail. comwrites:
              Hello, I am trying to write a library for buildding a kdtree for the
              3d mesh. I have uploaded my code on:
              >

              >
              Out of the four modules in the program, kdtree.c is the only one which
              is failing at line number 162 , subdivide_kdtre e function( I found
              this by using some printf statements and checking values). This is the
              statement that's failing:
              >
              kd->child[i]->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[i]->vertexlist = malloc(sizeof(v ector *) * (kd->child[i]->nvertices));
              k = 0;
              for(j = 0; j < kd->nvertices; j++)
              {
              if(vertex_insid e_box(kd->vertexlist[j], kd->split, axis, i))
              kd->child[i]->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[i]->vertexlist[k++] = kd->vertexlist[j];

              and loose the k += 1;.

              Also, you allocate space for kd->child[i]->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[i]->nvertices of the kd->nvertices
              vertexes pass the condition.

              --
              Ben.

              Comment

              • Keith Thompson

                #8
                Re: can some one please tell me the cause of the error ?

                pereges <Broli00@gmail. comwrites:
                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_kdtre e function( I found
                this by using some printf statements and checking values). This is the
                statement that's failing:
                >
                kd->child[i]->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?

                --
                Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                Nokia
                "We must do something. This is something. Therefore, we must do this."
                -- Antony Jay and Jonathan Lynn, "Yes Minister"

                Comment

                • rahul

                  #9
                  Re: can some one please tell me the cause of the error ?

                  On Jun 25, 11:05 pm, pereges <Brol...@gmail. comwrote:
                  Hello, I am trying to write a library for buildding a kdtree for the
                  3d mesh. I have uploaded my code on:
                  >

                  >
                  Out of the four modules in the program, kdtree.c is the only one which
                  is failing at line number 162 , subdivide_kdtre e function( I found
                  this by using some printf statements and checking values). This is the
                  statement that's failing:
                  >
                  kd->child[i]->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.

                  Comment

                  • pereges

                    #10
                    Re: can some one please tell me the cause of the error ?

                    On Jun 26, 2:01 am, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
                    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[i]->vertexlist = malloc(sizeof(v ector *) * (kd->child[i]->nvertices));
                    k = 0;
                    for(j = 0; j < kd->nvertices; j++)
                    {
                    if(vertex_insid e_box(kd->vertexlist[j], kd->split, axis, i))
                    kd->child[i]->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[i]->vertexlist[k++] = kd->vertexlist[j];
                    >
                    and loose the k += 1;.
                    thanks, this worked.

                    Also, you allocate space for kd->child[i]->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[i]->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[i] where i is 0 or
                    1). Yes, I must check that k == kd->child[i]->nvertices.

                    Comment

                    Working...