Fixed cleanup of html downloads

27-fixed-crash-with-html-image-downloads
Nimetu 3 years ago
parent a246f3e5d0
commit 8517bb72e1

@ -969,6 +969,7 @@ namespace NLGUI
// stop all curl downalods (html and data)
void releaseDownloads();
void releaseDataDownloads();
void checkDownloads();
// _CurlWWW download finished

@ -299,6 +299,11 @@ namespace NLGUI
void CGroupHTML::ImageDownloadCB::finish()
{
// Image setTexture will remove itself from Images while iterating over it.
// Do the swap to keep iterator safe.
std::vector<SImageInfo> vec;
vec.swap(Images);
// tmpdest file does not exist if download skipped (ie cache was used)
if (CFile::fileExists(tmpdest) || CFile::getFileSize(tmpdest) == 0)
{
@ -322,7 +327,7 @@ namespace NLGUI
// to temp file temporarily. that forces driver to reload texture from disk
// ITexture::touch() seem not to do this.
// cache was updated, first set texture as temp file
for(std::vector<SImageInfo>::iterator it = Images.begin(); it != Images.end(); ++it)
for(std::vector<SImageInfo>::iterator it = vec.begin(); it != vec.end(); ++it)
{
SImageInfo &img = *it;
Parent->setImage(img.Image, tmpdest, img.Type);
@ -339,7 +344,7 @@ namespace NLGUI
}
// even if image was cached, incase there was 'http://' image set to CViewBitmap
for(std::vector<SImageInfo>::iterator it = Images.begin(); it != Images.end(); ++it)
for(std::vector<SImageInfo>::iterator it = vec.begin(); it != vec.end(); ++it)
{
SImageInfo &img = *it;
Parent->setImage(img.Image, dest, img.Type);
@ -1053,6 +1058,13 @@ namespace NLGUI
_CurlWWW = NULL;
}
releaseDataDownloads();
}
void CGroupHTML::releaseDataDownloads()
{
LOG_DL("Clear pointers to %d curls", Curls.size());
// remove all queued and already started downloads
for(std::list<CDataDownload*>::iterator it = Curls.begin(); it != Curls.end(); ++it)
{
@ -3080,14 +3092,7 @@ namespace NLGUI
paragraphChange ();
// clear the pointer to the current image download since all the button are deleted
LOG_DL("Clear pointers to %d curls", Curls.size());
// remove image refs from downloads
/*for(std::list<CDataDownload>::iterator it = Curls.begin(); it != Curls.end(); ++it)
{
it->imgs.clear();
}*/
releaseDataDownloads();
}
// ***************************************************************************

@ -481,7 +481,13 @@ namespace NLGUI
}
else
{
_HtmlDownload = NULL;
if (_HtmlDownload)
{
CGroupHTML *groupHtml = dynamic_cast<CGroupHTML*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:webig:content:html"));
if (groupHtml)
groupHtml->removeImageDownload(_HtmlDownload, dynamic_cast<CViewBase*>(this));
_HtmlDownload = NULL;
}
_TextureId.setTexture (TxName.c_str (), _TxtOffsetX, _TxtOffsetY, _TxtWidth, _TxtHeight, false);
}
}

Loading…
Cancel
Save