weird behavior of rtcallable program

Calling a rtcallable program makes local variable nonsense.

rtCallableProgram(void, xs_eval, (int, CMPTYPE, CMPTYPE, CMPTYPE*,CMPTYPE*,CMPTYPE* ));

RT_PROGRAM void generate_ray()
  float x;
  x = 12;

    printf(x); //first print
    printf(x); //second print

    for(i=0;i<M;i++){ //M>=1
    printf(x); //third print

If steps=1, the 3 prints are 12,13,13;
If steps=2, the 3 prints in 2 loops are 12,13,12;12,13,12;
If value of steps is passed with a rtVariable, even when steps = 1, the 3 prints are 12,13,12.
If xs_eval() is not invoked, x values agree with expectation.

It’s hard to determine your intention with this function.


I assume this is an error (on line 8) and you meant to do istep++?

I meant to do istep++. That’s not the problem in the code but a typo when I copied here.