- // Don't change the binding in a mesh's vertex array object
- if(t==ELEMENT_ARRAY_BUFFER && Mesh::current())
- throw invalid_operation("Buffer::bind_to(ELEMENT_ARRAY_BUFFER)");
+ if(t==ELEMENT_ARRAY_BUFFER)
+ if(const Mesh *m = Mesh::current())
+ {
+ // Don't change the binding in a mesh's vertex array object
+ if(this==m->get_index_buffer())
+ return;
+ throw invalid_operation("Buffer::bind_to(ELEMENT_ARRAY_BUFFER)");
+ }