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

Unexpected '{' within function call in variable initialization #448

Open
remage opened this issue Aug 25, 2024 · 2 comments
Open

Unexpected '{' within function call in variable initialization #448

remage opened this issue Aug 25, 2024 · 2 comments

Comments

@remage
Copy link

remage commented Aug 25, 2024

Input:

vec3 cam_position = { 0.0, 0.0, 5.0 };
vec3 cam_target   = { 0.0, 0.0, 0.0 };
vec3 cam_dir = normalize(cam_target - cam_position);
vec3 cam_h = { 1.0f, 0.0f, 0.0f }; // fov_h = 90
vec3 cam_v = { 0.0f, 9.0/16.0, 0.0f };

It gets simplified to this code:

vec3 d={0.,0.,5.},c=normalize({0.,0.,0.}-d),l={1.f,0.f,0.f},r={0.f,.5625,0.f};

Shader compilation fails inside the normalize() call, with:

error C0000: syntax error, unexpected '{', expecting ')' at token "{"

@remage
Copy link
Author

remage commented Aug 25, 2024

Another experiment:

vec3 cam_position = { 0.0, 0.0, 5.0 };
vec3 cam_target   = { 0.0, 0.0, 0.0 };
vec3 cam_dir = { 0.0, 0.0, -1.0 }; // normalize(cam_target - cam_position);

This simplifies to:

vec3 d={0.,0.,5.},i={0.,0.,0.};
i={0.,0.,-1.};

It seems to try to reuse the variable i, but that assignment syntax fails to compile:

error C0000: syntax error, unexpected '{', expecting "::" at token "{"

It compiles when the assignment is fixed (by hand) to:

vec3 d={0.,0.,5.},i={0.,0.,0.};
i=vec3(0.,0.,-1.);

@remage
Copy link
Author

remage commented Aug 25, 2024

Further experiment: realizing that the fact cam_target gets reused means that it's not used anywhere else in the code...
So, in this case I can do this (and that is my workaround for now):

vec3 cam_position = { 0.0, 0.0, 5.0 };
// vec3 cam_target   = { 0.0, 0.0, 0.0 };
vec3 cam_dir = normalize(vec3(0.0, 0.0, 0.0) - cam_position);

This gets minified and then compiles correctly.

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

No branches or pull requests

1 participant