Skip to content

Commit

Permalink
Detect duplicated names when loading shaders (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Ji authored Jan 22, 2024
1 parent fb9d660 commit 54215ef
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dev/src/glshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ string ParseMaterialFile(string_view mbuf, string_view prefix) {
string defines;
string vfunctions, pfunctions, cfunctions, vertex, pixel, compute, vdecl, pdecl, csdecl, shader;
string *accum = nullptr;
set<string> shader_names;
auto word = [&]() {
p.remove_prefix(min(p.find_first_not_of(" \t\r"), p.size()));
size_t len = min(p.find_first_of(" \t\r"), p.size());
Expand All @@ -103,6 +104,12 @@ string ParseMaterialFile(string_view mbuf, string_view prefix) {
};
auto finish = [&]() -> bool {
if (!shader.empty()) {
if (shader_names.count(shader) == 1) {
err = cat("SHADER `", shader, "` is defined repeatedly!");
return true;
}
shader_names.insert(shader);

auto sh = make_unique<Shader>();
if (compute.length()) {
#ifdef PLATFORM_WINNIX
Expand Down

0 comments on commit 54215ef

Please sign in to comment.