Note that there are some explanatory texts on larger screens.

plurals
  1. POSegmentation fault while using std::map<std::string, GLuint>!
    text
    copied!<p>I have a Segmentation fault while using <code>std::map&lt;std::string, GLuint&gt;</code> (sic!). There are no visible pointers (where I could do something wrong) there! I don't know how it is possible. It doesn't occur in each place, only in <code>graphical_engine::draw(figure *f)</code> and in few places more (I think). Segmentation fault attacks me when I try to do something like: <code>cached["pos"] = 2</code>, <code>cached.begin()-&gt;first</code> etc.. But, step by step:</p> <p>Firstly I have to note that I'm using in this 'project' C++11. I do not know if that information will be helpful, but...</p> <p>I'm also using SFML library to open a window and write text in it.</p> <p>I am creating some graphic application in OpenGL. I got stuck in place where I created a kind of cache. I want to store in the cache an index of vertex attribute from a shader program. I simply don't want to 'charge' it using <code>glGetAttribLocation</code> more than once (the first time I call <code>glVertexAttribPointer</code> and the second time: use <code>glEnableVertexAttribArray</code>), so I've chose 'caching' it in <code>std::map&lt;std::string, GLuint&gt;</code>.</p> <p>In my application I've written a few classes responsible for: application logics, graphics. In graphics class I declared auxiliary types: <code>shader</code>, <code>shader_program</code>. I am writing it because when I call <code>s.is_cached("pos")</code> in, e.g <code>int main</code>, there is no Segmentation fault. The problem appears when I try to venture to call <code>s.is_cached("pos")</code> in my method <code>void graphics_engine::draw(figure *f)</code>. Then the famous Segmentation fault appears and it is not funny.</p> <p><code>bool shader_program::is_cached(const char *name)</code> implementation looks like:</p> <pre><code>bool shader_program::is_cached(const char *name) { std::string attrname = name; // p like 'pair' for(auto p: cached) { if(p.first == attrname) return true; } return false; } </code></pre> <p>Compilator <code>g++ (...) -std=c++0x</code> with an option <code>-g -D_GLIBCXX_DEBUG</code> produces code which interacts with my gdb and it returns</p> <pre><code>__gnu_debug::_Safe_sequence_base::_M_attach_single (this=0xb7b805c9, __it=0xbffff478, __constant=false) at ../../.././libstdc++-v3/src/debug.cc:274 274 __it-&gt;_M_next-&gt;_M_prior = __it; </code></pre> <p>If you don't understand any of my code, please, post a comment.</p> <p>The full code: <a href="http://jackweb.ovh.org/OGL.zip" rel="nofollow">http://jackweb.ovh.org/OGL.zip</a></p> <p>What causes the segmentation fault?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload