mirror of
https://github.com/JulianGro/overte.git
synced 2025-05-05 10:47:44 +02:00
make temp copy of NetworkPacket to protect against vector resizing
This commit is contained in:
parent
318b9b1671
commit
93ad1c3f99
1 changed files with 8 additions and 8 deletions
|
@ -91,23 +91,23 @@ bool PacketSender::process() {
|
||||||
while (keepGoing) {
|
while (keepGoing) {
|
||||||
uint64_t SEND_INTERVAL_USECS = (_packetsPerSecond == 0) ? USECS_PER_SECOND : (USECS_PER_SECOND / _packetsPerSecond);
|
uint64_t SEND_INTERVAL_USECS = (_packetsPerSecond == 0) ? USECS_PER_SECOND : (USECS_PER_SECOND / _packetsPerSecond);
|
||||||
|
|
||||||
|
lock();
|
||||||
NetworkPacket& packet = _packets.front();
|
NetworkPacket& packet = _packets.front();
|
||||||
|
NetworkPacket temporary = packet; // make a copy
|
||||||
|
_packets.erase(_packets.begin());
|
||||||
|
packetsLeft = _packets.size();
|
||||||
|
unlock();
|
||||||
|
|
||||||
// send the packet through the NodeList...
|
// send the packet through the NodeList...
|
||||||
UDPSocket* nodeSocket = NodeList::getInstance()->getNodeSocket();
|
UDPSocket* nodeSocket = NodeList::getInstance()->getNodeSocket();
|
||||||
|
|
||||||
nodeSocket->send(&packet.getAddress(), packet.getData(), packet.getLength());
|
nodeSocket->send(&temporary.getAddress(), temporary.getData(), temporary.getLength());
|
||||||
packetsThisCall++;
|
packetsThisCall++;
|
||||||
|
|
||||||
if (_notify) {
|
if (_notify) {
|
||||||
_notify->packetSentNotification(packet.getLength());
|
_notify->packetSentNotification(temporary.getLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
lock();
|
|
||||||
_packets.erase(_packets.begin());
|
|
||||||
unlock();
|
|
||||||
|
|
||||||
packetsLeft = _packets.size();
|
|
||||||
|
|
||||||
// in threaded mode, we go till we're empty
|
// in threaded mode, we go till we're empty
|
||||||
if (isThreaded()) {
|
if (isThreaded()) {
|
||||||
|
|
Loading…
Reference in a new issue