Print Page | Close Window

XTPImageManager::AddIcons appears to be buggy.

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: General Discussion
Forum Description: Topics Related to Visual C++ MFC Development in General
URL: http://forum.codejock.com/forum_posts.asp?TID=24418
Printed Date: 14 May 2024 at 8:36pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: XTPImageManager::AddIcons appears to be buggy.
Posted By: lviolette
Subject: XTPImageManager::AddIcons appears to be buggy.
Date Posted: 01 September 2023 at 6:57pm
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.1

Consider 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



Replies:
Posted By: lviolette
Date Posted: 01 September 2023 at 8:07pm
As a work-around, and possibly a more correct way to do this.  I updated the code to avoid a temporary CXTPImageManager and it "appears" to be functioning correctly.

void CMyXTPResizeDlg::UpdateImages()
{
    static UINT pnCommands[] = 
    {
        ID_WETRACK_AUTOKEY, ID_WETRACK_UPDATEKEY, ID_WETRACK_SCALEMODE
    };

    {
CXTPTempColorMask mask(RGB(255, 0, 255));
        XTPImageManager().SetIcons(IDPNG_TOOLBAR_WETRACK, pnCommands, 3, CSize(16, 16));
    }

    // This avoided the local image manager.
// From what I've seen so far, the buttons are showing correctly.
}



-------------
L. Violette
Monolith
www.lith.com
Xtreme Toolkit Pro v22.1.0


Posted By: agontarenko
Date Posted: 05 September 2023 at 4:54am
Hello,

Unfortunately we are unable to re-produce the problem. Can you please provide more detailed information and steps to take, screenshots or video can be useful as well. If it cannot be re-produced in any of our sample applications provided I would appreciate you sending a small code snippet or ideally a sample application so that we could debug it.

Regards,
Artem Gontarenko



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net