Segfault after mjr_maxViewport(&con)

Discussion in 'Visualization' started by bhairavm, May 8, 2018.

  1. Code:
        mjvScene scn = state->scn;
        mjrContext con = state->con;
        mjr_setBuffer(mjFB_OFFSCREEN, &con);
        mjrRect viewport = mjr_maxViewport(&con);
        mjr_render(viewport, &scn, &con);
        mjr_readPixels(rgb, NULL, viewport, &con);
    I run this piece of custom code in a loop. While the first time the image renders, on the second iteration, the code segfaults at mjr_render. Am I using these functions incorrectly?
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    I am going to assume your rgb buffer has enough space (if not, that can easily cause segfault).

    Normally you would call mjr_finish() or some version of swapbuffers() after each caller to mjr_render(). Without it, you end up filling the internal buffers of the video driver faster than it can render, and depending on how the driver is written, it could crash instead of returning an error message. I made the same mistake once (just before a DARPA demo :) and learned the hard way not to trust video drivers; so now I always call swapbuffers() after render().