The settings:
I'm trying to work with ImGUI
to draw gui on windows created using SDL. I wrote a function called update
in which it iterates over a forward_list
of drawable objects and draws them, and then I call it in my main after polling events.
The code:
//vsc++11
__interface IDrawable { void draw(ImDrawList * draw_list, ImVec2 margin = ImVec2 (20,20)); }
class DrawableObj0 : public IDrawable { ...; public void draw (ImDrawList * draw_list, ImVec2 margin = ImVec2 (20,20)) { ...; }; ... }
void update(forward_list<IDrawable *> * drawables) {
...;
for (auto it = drawables->begin(); it != drawables->end(); ++it)
(*it)->draw(...); // Gets Access Violation Exception!
...;
}
void main(...) {
forward_list<IDrawable *>* drawables = new forward_list<IDrawable *>();
DrawableObj0** x = new DrawableObj0*[5];
for (int i=0; i<5; i++){
x[i] = new DrawableObj0(...);
drawables->push_front(x[i]);
}
...;
update(drawables);
...;
}
The problem:
As I mentioned in the code section, I get memory access violation 0xc while trying to access the draw
function through the iterator. The visual studio shows that it can be resolved to the actual function in the watcher. I also tried it._Ptr->_myVal->draw
but it has the same result and crashes at the same memory offset as the code above.
Edited the code thanks to @kfsone