in this code, i make a list of all of the texture files available in a directory and create a guiimage for each. the images are placed into an array called ToolbarControls and then displayed as needed.
all of this works fine. the issue is when i change directories, i need to remove all of the toobarcontrols and rebuild based on the new directory. when I do this, i get leftover images that dont get removed.
Code: Select all
void setDirectory(stringc dirname)
{
destroyControls();
setSelectedItem(-1);
const irr::io::path OriginalWorkingDirectory = getDesktop()->getEngine()->getDevice()->getFileSystem()->getWorkingDirectory();
getDesktop()->getEngine()->getDevice()->getFileSystem()->changeWorkingDirectoryTo(dirname);
irr::io::IFileList* Files = getDesktop()->getEngine()->getDevice()->getFileSystem()->createFileList();
getDesktop()->getEngine()->getDevice()->getFileSystem()->changeWorkingDirectoryTo(OriginalWorkingDirectory);
for (unsigned int i = 0; i < Files->getFileCount(); i++)
{
if (!Files->isDirectory(i))
{
const irr::io::path filename = Files->getFullFileName(i);
ITexture* texture = Environment->getVideoDriver()->getTexture(filename.c_str());
if (texture)
{
IGUIImage* image = (IGUIImage*)addControl(Environment->addImage(rect<s32>(0, 0, 130, 30), this, -1, L"", false));
image->setImage(texture);
image->setScaleImage(true);
}
}
}
Files->drop();
}
};
virtual IGUIElement* addControl(IGUIElement* e)
{
m_ToolbarControls.push_back(e);
calculateLayout();
return e;
}
void destroyControls()
{
for (u32 x = 0; x < m_ToolbarControls.size(); x++)
{
m_ToolbarControls[x]->remove();
m_ToolbarControls.erase(x);
}
m_ToolbarControls.clear();
calculateLayout();
}
any thoughts on why this code
Code: Select all
void destroyControls()
{
for (u32 x = 0; x < m_ToolbarControls.size(); x++)
{
m_ToolbarControls[x]->remove();
m_ToolbarControls.erase(x);
}
m_ToolbarControls.clear();
calculateLayout();
}