[10139] Fix camera iteration in CameraCall function also dropped not needed for now viewpoint's member

(based on SilverIce's repo commit 885724b)

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
SilverIce 2010-07-02 21:41:48 +04:00 committed by VladimirMangos
parent f0fceda7bc
commit 87946f9c76
2 changed files with 6 additions and 17 deletions

View file

@ -64,37 +64,26 @@ class MANGOS_DLL_SPEC ViewPoint
friend class Camera; friend class Camera;
std::list<Camera*> m_cameras; std::list<Camera*> m_cameras;
std::list<Camera*>::iterator m_camera_iter;
GridType * m_grid; GridType * m_grid;
void Attach(Camera* c) { m_cameras.push_back(c); } void Attach(Camera* c) { m_cameras.push_back(c); }
void Detach(Camera* c) { m_cameras.remove(c); }
void Detach(Camera* c)
{
if (m_camera_iter != m_cameras.end() && *m_camera_iter == c) // detach called during the loop
m_camera_iter = m_cameras.erase(m_camera_iter);
else
m_cameras.remove(c);
}
void CameraCall(void (Camera::*handler)()) void CameraCall(void (Camera::*handler)())
{ {
if (!m_cameras.empty()) if (!m_cameras.empty())
{ {
for(m_camera_iter = m_cameras.begin(); m_camera_iter != m_cameras.end(); ++m_camera_iter) for(std::list<Camera*>::iterator itr = m_cameras.begin(); itr != m_cameras.end();)
{ {
((*m_camera_iter)->*handler)(); Camera *c = *(itr++);
(c->*handler)();
// can be end() after handler
if (m_camera_iter == m_cameras.end())
break;
} }
} }
} }
public: public:
ViewPoint() : m_grid(0), m_camera_iter(m_cameras.end()) {} ViewPoint() : m_grid(0) {}
~ViewPoint(); ~ViewPoint();
bool hasViewers() const { return !m_cameras.empty(); } bool hasViewers() const { return !m_cameras.empty(); }

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10138" #define REVISION_NR "10139"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__