GLSL while (someFunction) ... infinite loop

Hi,
I’ve had this issue a few times now. I’m trying to create a generator style function for iteration. A basic example would be:

bool iter(inout int i)
{
if (++i >= 10)
return false;
return true;
}

void main()
{
int i = 0;
int canary = 100;
while (iter(i))
{
if (–canary < 0)
break;
}
… //some code to show the value of canary

without canary, the while loop would be infinite,
however if I change it to
while (iter(i) == true)
the loop runs as expected and the canary is not triggered

is this a known bug, am I doing something stupid, or is the
“== true” test just the correct way to write it?
Has anyone else experienced this?

[EDIT]
this happens with nvidia 460GT (290.10). I just tested with ATI 5850 (catalyst 12.3) which doesn’t appear to have the issue. I’ll test with 295 shortly.

Sounds like a driver bug as while(iter(i)) should be equivalent with while(iter(i)==true) no matter what iter does as long as iter returns a bool result.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.