Vector out of bounds in Window::update

Create issue
Issue #221 resolved
Paul Turner created an issue


Text of OP from originator:

I am destroying windows while CEGUI is firing update events. This was resulting in a crash from vector out of bounds in: Code: void Window::update(float elapsed);

The cause is that the size of the vector is being cached, therefore if the size is reduced there will be a crash.

Code: size_t vectSize = getChildCount(); for (size_t i = 0; i < vectSize; ++i) d_children[i]->update(elapsed);

The solution to this is to not cache the variable and call getChildCount() from within the for loop declaration as follows.

Code: for (size_t i = 0; i < getChildCount(); ++i) d_children[i]->update(elapsed);

No more crashes, and with the inline any suitable compiler option selected should be a minimal performance overhead.

Reproducibility: have not tried

Comments (1)

  1. Log in to comment