summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-21 12:23:08 +0000
committerrubidium <rubidium@openttd.org>2009-01-21 12:23:08 +0000
commit40b776972326d3c673d3fb1c158b1e20dde8a95b (patch)
tree3bd6bdc69efbe82a4204c3e678df33c30b146376 /src/network
parent00aa88040e296788a6abe3fe759f4f3733ba48ab (diff)
downloadopenttd-40b776972326d3c673d3fb1c158b1e20dde8a95b.tar.xz
(svn r15195) -Fix: don't crash when removing from something you're iterating over
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network_content.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index 66c2c2d5d..f0521f0b5 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -750,29 +750,37 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
void ClientNetworkContentSocketHandler::OnConnect(bool success)
{
- for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); iter++) {
- (*iter)->OnConnect(success);
+ for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
+ ContentCallback *cb = *iter;
+ cb->OnConnect(success);
+ if (*iter != cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnDisconnect()
{
- for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); iter++) {
- (*iter)->OnDisconnect();
+ for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
+ ContentCallback *cb = *iter;
+ cb->OnDisconnect();
+ if (*iter != cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnReceiveContentInfo(const ContentInfo *ci)
{
- for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); iter++) {
- (*iter)->OnReceiveContentInfo(ci);
+ for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
+ ContentCallback *cb = *iter;
+ cb->OnReceiveContentInfo(ci);
+ if (*iter != cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnDownloadProgress(const ContentInfo *ci, uint bytes)
{
- for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); iter++) {
- (*iter)->OnDownloadProgress(ci, bytes);
+ for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
+ ContentCallback *cb = *iter;
+ cb->OnDownloadProgress(ci, bytes);
+ if (*iter != cb) iter++;
}
}
@@ -783,8 +791,10 @@ void ClientNetworkContentSocketHandler::OnDownloadComplete(ContentID cid)
ci->state = ContentInfo::ALREADY_HERE;
}
- for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); iter++) {
- (*iter)->OnDownloadComplete(cid);
+ for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
+ ContentCallback *cb = *iter;
+ cb->OnDownloadComplete(cid);
+ if (*iter != cb) iter++;
}
}