• R/O
  • SSH
  • HTTPS

tortoisesvn: Commit


Commit MetaInfo

Revision28317 (tree)
Time2018-07-27 02:30:53
Authorstefankueng

Log Message

Avoid a debug assertion in the revision graph by manually loading the toolbar resource and call SetButtons().

Change Summary

Incremental Difference

--- trunk/src/TortoiseProc/RevisionGraph/RevisionGraphDlg.cpp (revision 28316)
+++ trunk/src/TortoiseProc/RevisionGraph/RevisionGraphDlg.cpp (revision 28317)
@@ -43,6 +43,20 @@
4343
4444 using namespace Gdiplus;
4545
46+struct CToolBarData
47+{
48+ WORD wVersion;
49+ WORD wWidth;
50+ WORD wHeight;
51+ WORD wItemCount;
52+ //WORD aItems[wItemCount]
53+
54+ WORD* items()
55+ {
56+ return (WORD*)(this + 1);
57+ }
58+};
59+
4660 IMPLEMENT_DYNAMIC(CRevisionGraphDlg, CResizableStandAloneDialog)
4761 CRevisionGraphDlg::CRevisionGraphDlg(CWnd* pParent /*=NULL*/)
4862 : CResizableStandAloneDialog(CRevisionGraphDlg::IDD, pParent)
@@ -127,7 +141,34 @@
127141 // set up the toolbar
128142 // add the tool bar to the dialog
129143 m_ToolBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_WRAPABLE | TBSTYLE_TRANSPARENT | CBRS_SIZE_DYNAMIC);
130- m_ToolBar.LoadToolBar(IDR_REVGRAPHBAR);
144+
145+ // LoadToolBar() asserts in debug mode because the bitmap
146+ // fails to load. That's not a problem because we load the bitmap
147+ // further down manually.
148+ // but the assertion is ugly, so we load the button resource here
149+ // manually as well and call SetButtons().
150+ HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(IDR_REVGRAPHBAR), RT_TOOLBAR);
151+ HRSRC hRsrc = ::FindResource(hInst, MAKEINTRESOURCE(IDR_REVGRAPHBAR), RT_TOOLBAR);
152+ if (hRsrc == NULL)
153+ return FALSE;
154+
155+ HGLOBAL hGlobal = LoadResource(hInst, hRsrc);
156+ if (hGlobal == NULL)
157+ return FALSE;
158+
159+ auto pData = (CToolBarData*)LockResource(hGlobal);
160+ if (pData == NULL)
161+ return FALSE;
162+ ASSERT(pData->wVersion == 1);
163+
164+ auto pItems = std::make_unique<UINT[]>(pData->wItemCount);
165+ for (int i = 0; i < pData->wItemCount; i++)
166+ pItems[i] = pData->items()[i];
167+ m_ToolBar.SetButtons(pItems.get(), pData->wItemCount);
168+
169+ UnlockResource(hGlobal);
170+ FreeResource(hGlobal);
171+
131172 m_ToolBar.ShowWindow(SW_SHOW);
132173 m_ToolBar.SetBarStyle(CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY);
133174
Show on old repository browser