Pixie crashing with simple C program

Help
2009-01-06
2013-04-25
  • Gregor Mueckl
    Gregor Mueckl
    2009-01-06

    Hi!

    I tried to get into using Pixie through its C interface (the long term plan is to use the interface through JNA and embed Pixie as a renderer in Moonlight|3D). However, I managed to crash Pixie with a rather minimal example and cannot say what I'm doing wrong. I'm using Pixie 2.2.2 (provided through a Gentoo ebuild). The complete code for the program is:

    -- snip--
    #include "ri.h"

    int main()
    {
      RiBegin("");
      RiFrameBegin(1);
      RiFormat(640, 480, 1);
      RiDisplayV("test.tif", RI_FRAMEBUFFER, RI_RGB, 0, NULL, NULL);
      RiDisplayV("+test.tif", RI_FILE, RI_RGB, 0, NULL, NULL);
      RiProjection("perspective","fov",30.0);
    //  RiProjection("perspective");
    //  RiProjection(RI.RI_PERSPECTIVE,RI.RI_FOV,30.0f);
      RiWorldBegin();
      RiOrientation(RI_RH);
      RiAttributeBegin();
      RiSurfaceV(RI_CONSTANT, 0, NULL, NULL);
      RiTranslate(0, 0, 1);
      RiSphereV(0.3f, -0.3f, 0.3f, 360.0f, 0, NULL, NULL);
      RiAttributeEnd();
      RiLightSourceV("ambientlight", 0, NULL, NULL);
      RiWorldEnd();
      RiFrameEnd();
      RiEnd();
    }

    -- snip--

    The program crashes within the RiPerspective call. Not passing the fov parameter makes it work. Passing an equivalent scene to rndr works fine. Is there anything obvious that I might be doing wrong? I am unfortunately a complete newbie when it comes to using Renderman compatibles.

    Regards,
    Gregor

     
    • Moritz Moeller
      Moritz Moeller
      2009-01-06

      That's because you haven't terminated the token-value list passed to RiProjection() with a RI_NULL (I presume that was what you meant because your code doesn't contain any RiPerspective() calls and it shouldn't as this is not commonly used to define a viewing transformation for the image).
      Any Ri..() call that accepts a token-value list needs to end with RI_NULL. Or you could use the vector Ri..V() version (which btw. works great with STL vector<>).

      So this is not a Pixie issue but a PEBKAC one. ;)

      Note that it is advisable to use RI_NULL instead of NULL, to terminate token value lists in the RI.
      This is because the former will work correctly on 64 bit systems as well.

      At least this is the case for PRMan & 3Delight -- I just presume Pixie works the same way (doing a comparison with RI_NULL to find the end of the list). RI_NULL might be different from NULL, depending on architecture, compiler & OS.

      .mm

       
    • Moritz Moeller
      Moritz Moeller
      2009-01-06

      I  just noticed you terminate the other token-value Ri..() calls with two NULLs. Maybe that is a symptom of you already using a 64bit platform to compiler? :)
      One RI_NULL should be enough.

      .mm

       
    • Moritz Moeller
      Moritz Moeller
      2009-01-06

      Ignore my last comment.
      I looked again and noticed that you use the Ri..V() versions.

      Here, too though, you should use RI_NULL, RI_NULL to terminate the list, to be 64bit savvy although I guess if the number of tokens is 0, the pointers shouldn't even be touched by the function. :)

      Most people just use the token-value version, if no additional tokens are passed, i.e.:

      instead of:
        RiSurfaceV( RI_CONSTANT, 0, RI_NULL, RI_NULL );
      call
        RiSurface( RI_CONSTANT, RI_NULL );

      .mm

       
    • Gregor Mueckl
      Gregor Mueckl
      2009-01-06

      Hi!

      Thank you for the list of replies! I was actually expecting this to be user a simple error. As I said, I'm getting starting with the Renderman interface.

      And you are right: I wrote RiPerspective instead of RiProjection because this function constantly reminds me of gluPerspecitve (OpenGL is just a little bit too similar to RI :-) ). I noticed it too late to fix the post, though.

      However, I changed the line

      --snip--
        RiProjection("perspective","fov",30.0);
      --snip--

      to

      --snip--
        RiProjection("perspective","fov",30.0,RI_NULL);
      --snip--

      and the crash still happens. This is the gdb backtrace that I keep getting:

      --snip--
      #0  0x00007f2b50cc4452 in CRendererContext::RiProjectionV () from /usr/lib/libri.so.0
      #1  0x00007f2b50ce9bdd in RiProjection () from /usr/lib/libri.so.0
      #2  0x0000000000400dd9 in main ()
      --snip--

      When I deliberately misspell the fov parameter I get the following program output:

      --snip--
      Invalid perspective projection parameter (fo).
      Invalid perspective projection parameter ().
      --snip--

      The program still crashes inside the same function, but now inside a call to strcmp() (sorry, don't have line number information right now).

      I'd love to see this turn out as a user error on my part (less work for everybody), but I'm still at a loss...

      Regards,
      Gregor

       
      • Moritz Moeller
        Moritz Moeller
        2009-01-06

        I forgot, there's another issue: token-value pairs need to be passed as pointers both.
        So your code should look like this:

        RtFloat fov = 30;
        RiProjection("perspective","fov",&fov,RI_NULL);

        Sorry for missing this in my first reply. :)

        .mm

         
        • Gregor Mueckl
          Gregor Mueckl
          2009-01-09

          Hi!

          This fixed it for me. The value needs to be passed as a pointer. Now it also works when I call it from Java. Thanks!

          If anybody is interested, I can release the Java wrapper that I'm using.

          Regards,
          Gregor

           
    • Moritz Moeller
      Moritz Moeller
      2009-01-06

      There are btw. two projects on SF, Affogato & LiquidMaya, whose source should provide a rich source of how-to's, if you are binding a RMan renderer to a 3D modeling/animation app.

      .mm