From: <sv...@ww...> - 2005-01-05 06:56:41
|
Author: mkrose Date: 2005-01-04 22:56:30 -0800 (Tue, 04 Jan 2005) New Revision: 1437 Modified: trunk/CSP/SimCore/Battlefield/GlobalBattlefield.h trunk/CSP/SimCore/Battlefield/LocalBattlefield.cpp Log: Fix a possible segfault when new objects enter the battlefield. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1437 Modified: trunk/CSP/SimCore/Battlefield/GlobalBattlefield.h =================================================================== --- trunk/CSP/SimCore/Battlefield/GlobalBattlefield.h 2005-01-03 21:55:13 UTC (rev 1436) +++ trunk/CSP/SimCore/Battlefield/GlobalBattlefield.h 2005-01-05 06:56:30 UTC (rev 1437) @@ -262,6 +262,8 @@ response.send(queue); return; } + } else { + CSP_LOG(BATTLEFIELD, WARNING, "join request missing local time"); } PeerId id = msg->getSource(); Modified: trunk/CSP/SimCore/Battlefield/LocalBattlefield.cpp =================================================================== --- trunk/CSP/SimCore/Battlefield/LocalBattlefield.cpp 2005-01-03 21:55:13 UTC (rev 1436) +++ trunk/CSP/SimCore/Battlefield/LocalBattlefield.cpp 2005-01-05 06:56:30 UTC (rev 1437) @@ -356,7 +356,7 @@ msg->set_user_name(name); msg->set_internal_ip_addr(m_NetworkClient->getLocalNode().getIp()); msg->set_external_ip_addr(m_NetworkClient->getExternalNode().getIp()); - msg->set_local_time(simdata::getSecondsSinceUnixEpoch()); + msg->set_local_time(static_cast<simdata::uint32>(simdata::getSecondsSinceUnixEpoch())); sendServerCommand(msg); m_ConnectionState = CONNECTION_JOIN; } @@ -590,7 +590,9 @@ } bool LocalBattlefield::updateUnitVisibility(UnitWrapper *wrapper, GridPoint const &old_position, GridPoint const &new_position) { + assert(wrapper->unit().valid()); if (!m_SceneManager.valid()) return false; + if (!wrapper->unit().valid()) return false; const double vis_bubble = m_SceneManager->getVisibleRange(); const double vis_r2 = vis_bubble * vis_bubble; const bool in_old_bubble = (globalDistance2(m_CameraGridPosition, old_position) <= vis_r2) && !isNullPoint(old_position); @@ -659,13 +661,27 @@ CSP_LOG(BATTLEFIELD, DEBUG, "updateVisibility(): hiding " << hide.size() << " objects"); for (unsigned i = 0; i < hide.size(); ++i) { Object object = static_cast<ObjectWrapper*>(hide[i])->object(); - m_SceneManager->scheduleHide(object); + // object will be null if we have not received any peer updates yet. in this case + // the object isn't really visible, and there is nothing to do. this situation can + // arise transiently when new objects are added to the global battlefield, but in + // general we should have received peer updates before an object enters or leaves + // visible range. + if (object.valid()) { + m_SceneManager->scheduleHide(object); + } } CSP_LOG(BATTLEFIELD, DEBUG, "updateVisibility(): showing " << show.size() << " objects"); for (unsigned i = 0; i < show.size(); ++i) { Object object = static_cast<ObjectWrapper*>(show[i])->object(); - m_SceneManager->scheduleShow(object); + // object will be null if we have not received any peer updates yet. in this case + // we can't show the object, but the visibility will be reevaluated when the first + // update arives and the object is created. this situation can arise transiently + // when new objects are added to the global battlefield, but in general we should + // receive peer updates before an object enters visible range. + if (object.valid()) { + m_SceneManager->scheduleShow(object); + } } } |