# HG changeset patch # User koryspansel # Date 1317880546 25200 # Node ID f7095bce01cffdade2e1d49ed65cf37c9c1ce169 # Parent 41980ff0607dbcc7d9206c10a0367055f0846d05 Fix GuiElement destruction diff -r 41980ff0607d -r f7095bce01cf LightClone.smp Binary file LightClone.smp has changed diff -r 41980ff0607d -r f7095bce01cf LightClone/Source/ActionPanel.cpp --- a/LightClone/Source/ActionPanel.cpp Wed Oct 05 12:55:46 2011 -0700 +++ b/LightClone/Source/ActionPanel.cpp Wed Oct 05 22:55:46 2011 -0700 @@ -14,7 +14,7 @@ */ ActionPanel::ActionPanel(uint32 nWidth, uint32 nHeight) : GuiImage(), nSizeX(nWidth), nSizeY(nHeight) { - pSlot = new ActionSlot[nSizeX * nSizeY]; + pSlot = new ActionSlot*[nSizeX * nSizeY]; } /* @@ -38,15 +38,16 @@ { const uint32 nIndex = i * nSizeX + j; - pSlot[nIndex].Initialize(pServiceProvider); - pSlot[nIndex].SetTexture("Data\\Textures\\Slot.tga"); - pSlot[nIndex].SetDimensions(fSlotSizeX, fSlotSizeY); - pSlot[nIndex].SetPosition(fSlotPadding + (fSlotSizeX + fSlotSpacing) * j, fSlotPadding + (fSlotSizeY + fSlotSpacing) * i); - pSlot[nIndex].Subscribe(ActionSlot::EventDrop, &ActionPanel::OnActionDropped, this); - pSlot[nIndex].SetSlot(nIndex); - pSlot[nIndex].SetAction(Action_None); + pSlot[nIndex] = new ActionSlot(); + pSlot[nIndex]->Initialize(pServiceProvider); + pSlot[nIndex]->SetTexture("Data\\Textures\\Slot.tga"); + pSlot[nIndex]->SetDimensions(fSlotSizeX, fSlotSizeY); + pSlot[nIndex]->SetPosition(fSlotPadding + (fSlotSizeX + fSlotSpacing) * j, fSlotPadding + (fSlotSizeY + fSlotSpacing) * i); + pSlot[nIndex]->Subscribe(ActionSlot::EventDrop, &ActionPanel::OnActionDropped, this); + pSlot[nIndex]->SetSlot(nIndex); + pSlot[nIndex]->SetAction(Action_None); - Add(&pSlot[nIndex]); + Add(pSlot[nIndex]); } } } @@ -59,7 +60,7 @@ */ void ActionPanel::SetAction(uint32 nIndex, uint32 nAction) { - pSlot[nIndex].SetAction(nAction); + pSlot[nIndex]->SetAction(nAction); } /* @@ -67,7 +68,7 @@ */ uint32 ActionPanel::GetAction(uint32 nIndex) const { - return pSlot[nIndex].GetAction(); + return pSlot[nIndex]->GetAction(); } /* @@ -79,7 +80,7 @@ for(uint32 i = 0; i < nCount; ++i) { - pSlot[i].SetAction(Action_None); + pSlot[i]->SetAction(Action_None); } } @@ -92,7 +93,7 @@ for(uint32 i = 0; i < nCount; ++i) { - pSlot[i].SetPermanent(bPermanent); + pSlot[i]->SetPermanent(bPermanent); } } @@ -101,10 +102,10 @@ */ void ActionPanel::OnActionDropped(GuiEventArguments& kArguments) { - ActionSlot* pSlot = (ActionSlot*)kArguments.pSource; - ASSERT(pSlot != NULL); + ActionSlot* pActionSlot = (ActionSlot*)kArguments.pSource; + ASSERT(pActionSlot != NULL); - ActionArguments kActionArguments(this, pSlot->GetSlot()); + ActionArguments kActionArguments(this, pActionSlot->GetSlot()); Fire(ActionPanel::EventAction, kActionArguments); //TODO: Needed? diff -r 41980ff0607d -r f7095bce01cf LightClone/Source/ActionPanel.h --- a/LightClone/Source/ActionPanel.h Wed Oct 05 12:55:46 2011 -0700 +++ b/LightClone/Source/ActionPanel.h Wed Oct 05 22:55:46 2011 -0700 @@ -43,7 +43,7 @@ /* * pSlot */ - ActionSlot* pSlot; + ActionSlot** pSlot; /* * nSizeX diff -r 41980ff0607d -r f7095bce01cf LightClone/Source/ActionSlot.cpp --- a/LightClone/Source/ActionSlot.cpp Wed Oct 05 12:55:46 2011 -0700 +++ b/LightClone/Source/ActionSlot.cpp Wed Oct 05 22:55:46 2011 -0700 @@ -43,13 +43,6 @@ } /* - * Terminate - */ -void ActionSlot::Terminate() -{ -} - -/* * SetSlot */ void ActionSlot::SetSlot(uint32 nValue) diff -r 41980ff0607d -r f7095bce01cf LightClone/Source/ActionSlot.h --- a/LightClone/Source/ActionSlot.h Wed Oct 05 12:55:46 2011 -0700 +++ b/LightClone/Source/ActionSlot.h Wed Oct 05 22:55:46 2011 -0700 @@ -41,11 +41,6 @@ virtual ErrorCode Initialize(ServiceProvider* pServiceProvider); /* - * Terminate - */ - virtual void Terminate(); - - /* * SetSlot */ void SetSlot(uint32 nSlot); diff -r 41980ff0607d -r f7095bce01cf LightClone/Source/Bot.cpp --- a/LightClone/Source/Bot.cpp Wed Oct 05 12:55:46 2011 -0700 +++ b/LightClone/Source/Bot.cpp Wed Oct 05 22:55:46 2011 -0700 @@ -391,7 +391,7 @@ { Vertex::Block* pVertices = NULL; - HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD); + HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, 0); if(FAILED(hResult)) { return Error_Fail; diff -r 41980ff0607d -r f7095bce01cf LightClone/Source/Dialog.h --- a/LightClone/Source/Dialog.h Wed Oct 05 12:55:46 2011 -0700 +++ b/LightClone/Source/Dialog.h Wed Oct 05 22:55:46 2011 -0700 @@ -30,14 +30,14 @@ class Dialog : public GuiDialog { /* - * kLabel + * pLabel */ - GuiLabel kLabel; + GuiLabel* pLabel; /* - * kButton + * pButton */ - GuiButton kButton[ButtonCount]; + GuiButton* pButton[ButtonCount]; /* * kResult @@ -63,33 +63,35 @@ { SetTexture("Data\\Textures\\Dialog0.tga", true); - kLabel.Initialize(pServiceProvider); - kLabel.SetPosition(0.5f * kDimensions.x, 0.15f * kDimensions.y); - kLabel.SetLabelFlag(GuiLabelFlag_CenterX); - kLabel.SetFont("Courier New", 16); - kLabel.SetColor(D3DCOLOR_XRGB(0, 0, 0)); + pLabel = new GuiLabel(); + pLabel->Initialize(pServiceProvider); + pLabel->SetPosition(0.5f * kDimensions.x, 0.15f * kDimensions.y); + pLabel->SetLabelFlag(GuiLabelFlag_CenterX); + pLabel->SetFont("Courier New", 16); + pLabel->SetColor(D3DCOLOR_XRGB(0, 0, 0)); - Add(&kLabel); + Add(pLabel); for(uint32 i = 0; i < ButtonCount; ++i) { - kButton[i].Initialize(pServiceProvider); - kButton[i].SetTexture(GuiButtonState_Normal, "Data\\Textures\\ButtonN.tga", true); - kButton[i].SetTexture(GuiButtonState_Hover, "Data\\Textures\\ButtonH.tga"); - kButton[i].SetTexture(GuiButtonState_Down, "Data\\Textures\\ButtonD.tga"); - kButton[i].SetFont("Courier New", 16); - kButton[i].SetColor(D3DCOLOR_XRGB(0, 0, 0)); - kButton[i].Subscribe(GuiButton::EventClick, &Dialog::OnClick, this); + pButton[i] = new GuiButton(); + pButton[i]->Initialize(pServiceProvider); + pButton[i]->SetTexture(GuiButtonState_Normal, "Data\\Textures\\ButtonN.tga", true); + pButton[i]->SetTexture(GuiButtonState_Hover, "Data\\Textures\\ButtonH.tga"); + pButton[i]->SetTexture(GuiButtonState_Down, "Data\\Textures\\ButtonD.tga"); + pButton[i]->SetFont("Courier New", 16); + pButton[i]->SetColor(D3DCOLOR_XRGB(0, 0, 0)); + pButton[i]->Subscribe(GuiButton::EventClick, &Dialog::OnClick, this); // assumes all buttons are equally sized - const float fWidth = kButton[i].GetDimensions().x; + const float fWidth = pButton[i]->GetDimensions().x; const float fPadding = (kDimensions.x - ButtonCount * fWidth) / (float)(ButtonCount + 1); const float fX = fPadding + i * (fWidth + fPadding); const float fY = 0.65f * kDimensions.y; - kButton[i].SetPosition(fX, fY); + pButton[i]->SetPosition(fX, fY); - Add(&kButton[i]); + Add(pButton[i]); } } @@ -107,7 +109,7 @@ char kBuffer[128]; vsprintf(kBuffer, pFormat, kArguments); - kLabel.SetText(kBuffer); + pLabel->SetText(kBuffer); va_end(kArguments); } @@ -117,7 +119,7 @@ */ void SetButton(uint32 nButton, const char* pText, uint32 nResult) { - kButton[nButton].SetText(pText); + pButton[nButton]->SetText(pText); kResult[nButton] = nResult; } @@ -130,7 +132,7 @@ { for(uint32 nButton = 0; nButton < ButtonCount; ++nButton) { - if(kArguments.pSource == &kButton[nButton]) + if(kArguments.pSource == pButton[nButton]) { Close(kResult[nButton]); } diff -r 41980ff0607d -r f7095bce01cf LightClone/Source/Environment.cpp --- a/LightClone/Source/Environment.cpp Wed Oct 05 12:55:46 2011 -0700 +++ b/LightClone/Source/Environment.cpp Wed Oct 05 22:55:46 2011 -0700 @@ -337,7 +337,7 @@ { Vertex::Block* pVertices = NULL; - HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD); + HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, 0); if(FAILED(hResult)) { return Error_Fail; diff -r 41980ff0607d -r f7095bce01cf LightClone/Source/GuiElement.cpp --- a/LightClone/Source/GuiElement.cpp Wed Oct 05 12:55:46 2011 -0700 +++ b/LightClone/Source/GuiElement.cpp Wed Oct 05 22:55:46 2011 -0700 @@ -27,6 +27,12 @@ */ GuiElement::~GuiElement() { + for(uint32 i = 0; i < kChildren.Size(); ++i) + { + delete kChildren[i]; + } + + kChildren.Clear(); } /* diff -r 41980ff0607d -r f7095bce01cf LightClone/ToDo.txt --- a/LightClone/ToDo.txt Wed Oct 05 12:55:46 2011 -0700 +++ b/LightClone/ToDo.txt Wed Oct 05 22:55:46 2011 -0700 @@ -2,6 +2,7 @@ 1. Main menu 2. Pause menu 3. Additional maps +4. Add memory leak detection Polish: 1. Button tool tips