aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/fullpipe/messages.cpp21
-rw-r--r--engines/fullpipe/messages.h3
2 files changed, 19 insertions, 5 deletions
diff --git a/engines/fullpipe/messages.cpp b/engines/fullpipe/messages.cpp
index d856d1beaf..bd8dff8009 100644
--- a/engines/fullpipe/messages.cpp
+++ b/engines/fullpipe/messages.cpp
@@ -263,7 +263,7 @@ MessageQueue::MessageQueue(MessageQueue *src, int parId, int field_38) {
_id = g_fp->_globalMessageQueueList->compact();
_dataId = src->_dataId;
- _flags = src->_flags;
+ _flags = src->_flags & ~kInGlobalQueue;
_queueName = "";
g_fp->_globalMessageQueueList->addMessageQueue(this);
@@ -319,7 +319,6 @@ bool MessageQueue::chain(StaticANIObject *ani) {
if (checkGlobalExCommandList1() && checkGlobalExCommandList2()) {
if (!(getFlags() & kInGlobalQueue)) {
g_fp->_globalMessageQueueList->addMessageQueue(this);
- _flags |= kInGlobalQueue;
}
if (ani) {
ani->queueMessageQueue(this);
@@ -656,9 +655,23 @@ int GlobalMessageQueueList::compact() {
}
void GlobalMessageQueueList::addMessageQueue(MessageQueue *msg) {
- msg->setFlags(msg->getFlags() | kInGlobalQueue);
+ if ((msg->getFlags() & kInGlobalQueue) == 0) {
+ msg->setFlags(msg->getFlags() | kInGlobalQueue);
+ push_back(msg);
+ } else {
+ warning("Trying to add a MessageQueue already in the queue");
+ }
+}
- push_back(msg);
+void GlobalMessageQueueList::clear() {
+ for (iterator it = begin(); it != end(); ++it) {
+ // The MessageQueue destructor will try to remove itself from the global
+ // queue if it thinks it is in the global queue, which will break the
+ // iteration over the list
+ (*it)->_flags &= ~kInGlobalQueue;
+ delete *it;
+ }
+ Common::Array<MessageQueue *>::clear();
}
void clearGlobalMessageQueueList() {
diff --git a/engines/fullpipe/messages.h b/engines/fullpipe/messages.h
index 91677a172d..71ec962c7c 100644
--- a/engines/fullpipe/messages.h
+++ b/engines/fullpipe/messages.h
@@ -163,13 +163,14 @@ class MessageQueue : public CObject {
};
class GlobalMessageQueueList : public Common::Array<MessageQueue *> {
- public:
+public:
MessageQueue *getMessageQueueById(int id);
void deleteQueueById(int id);
void removeQueueById(int id);
void disableQueueById(int id);
/** `msg` becomes owned by `this` */
void addMessageQueue(MessageQueue *msg);
+ void clear();
int compact();
};