X-Git-Url: http://git.tdb.fi/?p=libs%2Fgltk.git;a=blobdiff_plain;f=source%2Fpartcache.cpp;h=3c3fbb169e3e2c20b707f20b6bdb25f656fc94fd;hp=4747cb50b3e585fd45bb6a5be8fe864bd2937266;hb=caa04d76bc031dd0c4a4157732deb340d934ceeb;hpb=2a665655a15f73d59083fd5cc7e5a58ae5f4d377 diff --git a/source/partcache.cpp b/source/partcache.cpp index 4747cb5..3c3fbb1 100644 --- a/source/partcache.cpp +++ b/source/partcache.cpp @@ -18,8 +18,16 @@ CachedPart::~CachedPart() } +PartCache::PartCache(): + rebuilding(false) +{ } + void PartCache::begin_rebuild() { + if(rebuilding) + throw logic_error("nested rebuild"); + rebuilding = true; + next = parts.begin(); current = parts.end(); } @@ -28,6 +36,8 @@ void PartCache::insert_special(const Part &part) { if(part.get_name().empty()) throw invalid_argument("PartCache::insert_special"); + if(!rebuilding) + throw logic_error("!rebuilding"); for(current=next; current!=parts.end(); ++current) if(current->part==&part) @@ -48,6 +58,9 @@ void PartCache::insert_special(const Part &part) GL::Mesh &PartCache::create_mesh(const Part &part, const GL::Texture2D &tex) { + if(!rebuilding) + throw logic_error("!rebuilding"); + if(current!=parts.end() && current->texture==&tex) return *current->mesh; @@ -76,6 +89,7 @@ GL::Mesh &PartCache::create_mesh(const Part &part, const GL::Texture2D &tex) void PartCache::end_rebuild() { + rebuilding = false; parts.erase(next, parts.end()); }