* Fix a bug where some event chains could result in reading from a
  freed memory space.
This commit is contained in:
jean.chalard
2009-09-04 17:21:34 +00:00
parent 01fe3b76f7
commit c8af1836a0
2 changed files with 21 additions and 5 deletions

View File

@@ -17,11 +17,21 @@ CardGui::CardGui(MTGCardInstance* card, float x, float y) : PlayGuiObject(Height
CardGui::CardGui(MTGCardInstance* card, const Pos& ref) : PlayGuiObject(Height, ref, false), card(card) {} CardGui::CardGui(MTGCardInstance* card, const Pos& ref) : PlayGuiObject(Height, ref, false), card(card) {}
CardView::CardView(MTGCardInstance* card, float x, float y) : CardGui(card, x, y) { CardView::CardView(MTGCardInstance* card, float x, float y) : CardGui(card, x, y) {
card->view = this; const Pos* ref = card->view;
while (card)
{
if (ref == card->view) card->view = this;
card = card->next;
}
} }
CardView::CardView(MTGCardInstance* card, const Pos& ref) : CardGui(card, ref) { CardView::CardView(MTGCardInstance* card, const Pos& ref) : CardGui(card, ref) {
card->view = this; const Pos* r = card->view;
while (card)
{
if (r == card->view) card->view = this;
card = card->next;
}
} }
void CardGui::Update(float dt) void CardGui::Update(float dt)

View File

@@ -135,11 +135,17 @@ int DuelLayers::receiveEvent(WEvent * e){
Pos* p; Pos* p;
if (WEventZoneChange *event = dynamic_cast<WEventZoneChange*>(e)) if (WEventZoneChange *event = dynamic_cast<WEventZoneChange*>(e))
{ {
if (event->card->view) MTGCardInstance* card = event->card;
waiters.push_back(p = NEW Pos(*(event->card->view))); if (card->view)
waiters.push_back(p = NEW Pos(*(card->view)));
else else
waiters.push_back(p = NEW Pos(0, 0, 0, 0, 255)); waiters.push_back(p = NEW Pos(0, 0, 0, 0, 255));
event->card->view = p; const Pos* ref = card->view;
while (card)
{
if (ref == card->view) card->view = p;
card = card->next;
}
} }
} }
for (int i = 0; i < nbitems; ++i) for (int i = 0; i < nbitems; ++i)