Fixed: Crash when CViewBitmap was using texture from web.

--HG--
branch : develop
hg/ark
Nimetu 5 years ago
parent b822f1388e
commit bbfc20c81d

@ -125,6 +125,8 @@ namespace NLGUI
// add image download (used by view_bitmap.cpp to load web images)
void addImageDownload(const std::string &url, CViewBase *img, const CStyleParams &style = CStyleParams(), const TImageType type = NormalImage);
// remove image from download list if present
void removeImageDownload(CViewBase *img);
std::string localImageName(const std::string &url);
// Timeout

@ -56,8 +56,14 @@ namespace NLGUI
_TxtOffsetY = 0;
_TxtWidth = -1;
_TxtHeight = -1;
// Support for https://.. textures
_HtmlDownload = false;
}
/// Destructor
virtual ~CViewBitmap();
std::string getProperty( const std::string &name ) const;
void setProperty( const std::string &name, const std::string &value );
xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const;
@ -132,6 +138,7 @@ namespace NLGUI
bool _Flip : 1;
bool _Tile : 1;
bool _InheritGCAlpha : 1;
bool _HtmlDownload : 1;
// For single texture

@ -740,6 +740,24 @@ namespace NLGUI
pumpCurlQueue();
}
void CGroupHTML::removeImageDownload(CViewBase *img)
{
for(std::list<CDataDownload>::iterator it = Curls.begin(); it != Curls.end(); ++it)
{
// check all active downloads because image does not keep url around
std::vector<CDataImageDownload>::iterator imgIter = it->imgs.begin();
while(imgIter != it->imgs.end())
{
if (imgIter->Image == img)
{
it->imgs.erase(imgIter);
break;
}
++imgIter;
}
}
}
void CGroupHTML::initImageDownload()
{
LOG_DL("Init Image Download");

@ -37,6 +37,18 @@ REGISTER_UI_CLASS(CViewBitmap)
namespace NLGUI
{
CViewBitmap::~CViewBitmap()
{
if (_HtmlDownload)
{
CGroupHTML *groupHtml = dynamic_cast<CGroupHTML*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:webig:content:html"));
if (groupHtml) {
_HtmlDownload = false;
groupHtml->removeImageDownload(dynamic_cast<CViewBase*>(this));
}
}
}
std::string CViewBitmap::getProperty( const std::string &name ) const
{
if( name == "color" )
@ -461,6 +473,7 @@ namespace NLGUI
if (!CFile::fileExists(localname))
localname = "web_del.tga";
_TextureId.setTexture (localname.c_str(), _TxtOffsetX, _TxtOffsetY, _TxtWidth, _TxtHeight, false);
_HtmlDownload = true;
groupHtml->addImageDownload(TxName, dynamic_cast<CViewBase*>(this));
}
}

Loading…
Cancel
Save