Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > General Discussion
  New Posts New Posts RSS Feed - XTPImageManager::AddIcons appears to be buggy.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

XTPImageManager::AddIcons appears to be buggy.

 Post Reply Post Reply
Author
Message
lviolette View Drop Down
Groupie
Groupie
Avatar

Joined: 17 March 2007
Location: United States
Status: Offline
Points: 60
Post Options Post Options   Thanks (0) Thanks(0)   Quote lviolette Quote  Post ReplyReply Direct Link To This Post Topic: XTPImageManager::AddIcons appears to be buggy.
    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
Back to Top
lviolette View Drop Down
Groupie
Groupie
Avatar

Joined: 17 March 2007
Location: United States
Status: Offline
Points: 60
Post Options Post Options   Thanks (0) Thanks(0)   Quote lviolette Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
agontarenko View Drop Down
Admin Group
Admin Group


Joined: 25 March 2016
Status: Offline
Points: 260
Post Options Post Options   Thanks (0) Thanks(0)   Quote agontarenko Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.