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

@include file in different blocks errors out as Detected @include file cycle #55

Open
legends2k opened this issue Jun 5, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@legends2k
Copy link

legends2k commented Jun 5, 2021

I've a util.glsl from which I use some functions in pnt.glsl:

@vs vs

@include util.glsl

@end

@fs fs

@include util.glsl

@end

this leads to

util.glsl:60:0: error: Detected @include file cycle: 'util.glsl'

OTOH skipping an include leads to

no matching overloaded function found

Moving the @include outside both blocks doesn't solve the issue either.

@floooh
Copy link
Owner

floooh commented Jun 8, 2021

Hmm, yeah, I can confirm. The bug must be somehere around here:

// check for include cycles
for (const std::string& filename : inp.filenames) {
if (filename == path_used) {
inp.out_error = errmsg_t::error(inp.filenames.back(), parent_line_index, fmt::format("Detected @include file cycle: '{}'", path_used));
return false;
}
}

I haven't written the file-include code though and need to investigate what's going on there (or if you find anything I'd be thankful for a PR).

@floooh floooh added the bug Something isn't working label Jun 8, 2021
@legends2k
Copy link
Author

Before going deep, file cycle here means a.glsl including b.glsl and b.glsl including a.glsl, right?

@floooh
Copy link
Owner

floooh commented Jun 10, 2021

Yeah, or even more complex things like a.glsl including b.glsl, b.glsl including c.glsl, and c.glsl including a.glsl, basically anything that would result in an infinite loop when resolving the includes.

@legends2k
Copy link
Author

legends2k commented Jun 10, 2021

Got it; it could be a linked list but not circular.

I think the current check checks for > 1 inclusion of a file in a TU but it has to be made in a block i.e. once for @vs and once for @fs is okay.

I just built sokol-tools project locally, will try debugging when time permits.

@legends2k
Copy link
Author

legends2k commented Jun 11, 2021

The backtrace

  * frame #0: 0x000000010002a06e sokol-shdc`shdc::load_and_preprocess(path="util.glsl", include_dirs=size=1, inp=0x00007ffeefbfeba8, parent_line_index=34) at input.cc:478:45
    frame #1: 0x000000010002a38c sokol-shdc`shdc::load_and_preprocess(path="pnt.glsl", include_dirs=size=1, inp=0x00007ffeefbfeba8, parent_line_index=0) at input.cc:511:22
    frame #2: 0x0000000100029c48 sokol-shdc`shdc::input_t::load_and_parse(path="pnt.glsl", module_override="") at input.cc:542:9
    frame #3: 0x000000010003d4b5 sokol-shdc`main(argc=9, argv=0x00007ffeefbfede8) at main.cc:21:19

shows the current implementation does the loading (and preprocessing) per-file; this needs to be changed to per-block for checking and allowing same file inclusion per-block.

@legends2k
Copy link
Author

legends2k commented Jun 11, 2021

I found a side-stepping solution to this issue

@block util
@include util.glsl
@end

@vs vs
@include_block util
// use methods from util.glsl
@end

@fs fs
@include_block util
// use methods from util.glsl
@end

Basically, include required file once inside a separate block. A block needing some functions from the included file -- e.g. vs1, fs1, ... -- can @include_block and use them!

This workaround seems sufficient for me, if this is fix enough please go ahead and close this @floooh.

@legends2k legends2k changed the title @include file once in vs and once in fs errors out as "Detected @include file cycle" @include file in different blocks errors out as "Detected @include file cycle" Jun 11, 2021
@legends2k legends2k changed the title @include file in different blocks errors out as "Detected @include file cycle" @include file in different blocks errors out as Detected @include file cycle Jun 11, 2021
@floooh
Copy link
Owner

floooh commented Jun 25, 2021

Yep, I was coming back to suggest the block workaround, but you already found it :)

I'll keep the bug open in case I get around a "proper" fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants