Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compression converts else if to elseif #6

Open
micahjon opened this issue Sep 10, 2020 · 2 comments · May be fixed by #8
Open

Compression converts else if to elseif #6

micahjon opened this issue Sep 10, 2020 · 2 comments · May be fixed by #8

Comments

@micahjon
Copy link

H, I noticed that compressing this shader code:

    }else
    if (mode == 1.0){ // GROW

        offsetStrength *= 0.25;

Results in the following string:

}elseif(mode==1.0){offsetStrength*=0.25;

Where else if is converted to elseif

I'm guessing this is unintentional. My understanding is that elseif is not valid syntax for GLSL, or at least not widely supported. I realize having else if on separate lines is also strange, but I'm working with a large legacy codebase and figured compression shouldn't impact the output, as long as the input is valid.

Thanks for looking into this!

@sotrh
Copy link

sotrh commented May 24, 2022

I'm also having this problem but with else blocks with no {}. Consider the following code:

// Copied from ThreeJS
float getFace( vec3 direction ) {
	vec3 absDirection = abs( direction );
	float face = - 1.0;
	if ( absDirection.x > absDirection.z ) {
		if ( absDirection.x > absDirection.y )
			face = direction.x > 0.0 ? 0.0 : 3.0;
		else
			face = direction.y > 0.0 ? 1.0 : 4.0;
	} else {
		if ( absDirection.z > absDirection.y )
			face = direction.z > 0.0 ? 2.0 : 5.0;
		else
			face = direction.y > 0.0 ? 1.0 : 4.0;
	}
	return face;
}

The else blocks get compressed into the contained statement resulting in elseface. Adding {} around the block is a good work around for me, but the compression should not break the code.

@micahjon
Copy link
Author

@vwochnik , just submitted a PR that should fix this issue. Thanks for considering!
#8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants