From 663de25cbeb9f917c49ba98f8e5f0b6ecafb0caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Meelis=20M=C3=A4gi?= Date: Mon, 3 Jan 2022 10:20:02 +0000 Subject: [PATCH] Fixed cleanup of html downloads --- nel/include/nel/gui/group_html.h | 1 + nel/src/gui/group_html.cpp | 25 +++++++++++++++---------- nel/src/gui/view_bitmap.cpp | 8 +++++++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/nel/include/nel/gui/group_html.h b/nel/include/nel/gui/group_html.h index 8b6ad19b6..4f972b191 100644 --- a/nel/include/nel/gui/group_html.h +++ b/nel/include/nel/gui/group_html.h @@ -969,6 +969,7 @@ namespace NLGUI // stop all curl downalods (html and data) void releaseDownloads(); + void releaseDataDownloads(); void checkDownloads(); // _CurlWWW download finished diff --git a/nel/src/gui/group_html.cpp b/nel/src/gui/group_html.cpp index 107ab107a..de7e6effe 100644 --- a/nel/src/gui/group_html.cpp +++ b/nel/src/gui/group_html.cpp @@ -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 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::iterator it = Images.begin(); it != Images.end(); ++it) + for(std::vector::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::iterator it = Images.begin(); it != Images.end(); ++it) + for(std::vector::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::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::iterator it = Curls.begin(); it != Curls.end(); ++it) - { - it->imgs.clear(); - }*/ + releaseDataDownloads(); } // *************************************************************************** diff --git a/nel/src/gui/view_bitmap.cpp b/nel/src/gui/view_bitmap.cpp index 89c944a18..1896ced40 100644 --- a/nel/src/gui/view_bitmap.cpp +++ b/nel/src/gui/view_bitmap.cpp @@ -481,7 +481,13 @@ namespace NLGUI } else { - _HtmlDownload = NULL; + if (_HtmlDownload) + { + CGroupHTML *groupHtml = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:webig:content:html")); + if (groupHtml) + groupHtml->removeImageDownload(_HtmlDownload, dynamic_cast(this)); + _HtmlDownload = NULL; + } _TextureId.setTexture (TxName.c_str (), _TxtOffsetX, _TxtOffsetY, _TxtWidth, _TxtHeight, false); } }