Code that worked in 18.3, but appears to be broken in 22.1. This code is lead-up to a crash I'm having while migrating to 22.1Consider the following:
void CMyXTPResizeDlg::UpdateImages() { static UINT pnCommands[] = { ID_WETRACK_AUTOKEY, ID_WETRACK_UPDATEKEY, ID_WETRACK_SCALEMODE };
{ CXTPImageManager localImageManager; localImageManager.SetMaskColor(RGB(255, 0, 255)); localImageManager.SetIcons(IDPNG_TOOLBAR_WETRACK, pnCommands, 3, CSize(16, 16)); GetCommandBars()->GetImageManager()->AddIcons(&localImageManager); }
// When the iconsets were copied over, their CXTPImageManager* member was NOT updated. // They are still pointing at localImageManager even though are actually in the dialog's image manager. // This results in a crash down the line. }
|
Attempt to explain why we crash...
void CXTPImageManager::AddIcons(CXTPImageManager* pImageManager)
|
This function adds icons from one image manager to another. It does so by iterating over the icons, retrieving each iconset and passing the iconset to
void CXTPImageManager::AddIcons(CXTPImageManagerIconSet* pIconSetAdd)
|
This function then iterates over the various icons in the icons set and adds them to the iconset of the image manager. But, it does so by constructing a CXTPImageManagerIcon like so:
pIcon = new CXTPImageManagerIcon(pIconSetAdd->GetID(), pIconSetAdd, CSize(XTPToIntChecked(nWidth), 0));
|
That pIconSetAdd is actually (&localImageManager). And it's being used as the image manager in this new icon. Which is invalid. This logic has changed since 18.3.
In 22.1, it crashes in CXTPImageManager::SetIcon(const CXTPImageManagerIconHandle& hIcon) because I am updating one of the images and it hits this code:
if (m_pIconSet) m_pIconSet->RefreshAll();
|
Since m_pIconSet is pointing to the deleted localImageManager, it crashes. In 18.3 m_pIconSet here would have been nullptr, so it would have skipped calling RefreshAll.
My question is... Is CXTPImageManager::AddIcons(CXTPImageManager* pImageManager) working as intended? Is it suppose to take the images in pImageManager, add them to "this", but leave them with pointers to pImageManager rather than "this"?
I'd like an answer to this before I rewrite this code I inherited to add the icons the to image manager and correctly set the iconset's m_pImageManager pointer.
------------- L. Violette Monolith www.lith.com Xtreme Toolkit Pro v22.1.0
|