mity / mctrl

C library providing set of additional user interface controls for Windows, intended to be complementary to standard Win32API controls from USER32.DLL and COMCTL32.DLL.
http://mctrl.org
235 stars 52 forks source link

[TreeList] Exception on MC_TLN_GETSUBDISPINFO #46

Closed Bugzero71 closed 7 years ago

Bugzero71 commented 7 years ago

Martin, TreeList is throwing an exception when a subitem must be defined and it's not. I'm using MC_LPSTR_TEXTCALLBACKW to define a subitem text and an assertion is thrown if value in DispInfo struct pszText is not defined. In fact it is not previously defined as nullptr.

It's easy to correct. Only add in treelist.c, line 403:

    info.subitem.pszText = NULL;            // Prevent from exception

That's all

Bugzero71 commented 7 years ago

Martin, I've got some new exceptions in treelist_free_subdispinfo(...). This function is freeing a pointer which I was assuming that it should be controlled by application. This is not the way Grid is working.

My code in MC_TLN_GETDISPINFOW is like this:

  MC_NMTLSUBDISPINFOW* lpDispInfo = (MC_NMTLSUBDISPINFOW*)pNotifyStruct;

  if (lpDispInfo != nullptr
     && m_pMemory_ != nullptr)
  {
    ELOGIC::label_id_t label_id = GET_LABID(lpDispInfo->lItemParam);

    if (label_id != ELOGIC::INVALID_LABEL_ID)
    {
       MC_TLSUBITEMW& subitem = lpDispInfo->subitem;

       wsprintf(m_szTempBuffer_, L"%ld", m_pMemory_->GetLabelValue(label_id));
       subitem.pszText = m_szTempBuffer_;
    }
  }

  *pResult = TRUE;

The line free(si-text) shown in piece of code below, obviously throws exception.

static inline void
treelist_free_subdispinfo(treelist_t* tl, treelist_item_t* item, int subitem_id,
                          treelist_subdispinfo_t* si)
{
    if(si->text != NULL  &&  (!item->has_alloced_subitems || si->text != item->subitems[subitem_id-1]))
        free(si->text);
}
mity commented 7 years ago

I committed some fixes.

Please next time rather open new issue for each bug. If you include multiple into single thread, I cannot reasonable refer to single bug from a commit, and if there is a longer discussion for multiple bugs in single report it's messy to read.

Bugzero71 commented 7 years ago

OK, Martin no exception is thrown at this moment and values are updated as expected.