Tool bar icon problem

Post here wxCrafter related issues / features / bugs
coder99
CodeLite Expert
Posts: 143
Joined: Wed Oct 22, 2008 6:50 am
Contact:

Tool bar icon problem

Post by coder99 » Thu Nov 30, 2017 12:09 am

Running wxCrafter 2.7 with wxWidgets 3.1.0 & MSVC 2015 under Win 10 64-bit
Recently I added some new icons from the crystal set to my app.
The icons are part of a tool bar in a dialog, in case it make any difference.
One set of PNG images loads and displays OK, the other does not.
I have asked on the wxWidgets forum and the issue seems to relate to the use of wxXmlResource to load the images.
The topic URL is https://forums.wxwidgets.org/viewtopic. ... 37#p180737
The images which cause issues are 'different' in that they are bigger than the ones which do not cause an issue.
I'll attach one copy of either set.
The main reason I am posting here is because I do not know or understand how the PNG files are translated to XML file and thus am unable to decide where to look for a solution to the problem.

Code: Select all

#if 0
    wxBitmap wbmTest;
    wbmTest.LoadFile( _("D:/pkg/wx/MSVC2015/_3.1-2015/wxGTM/rc/edit_add.png"),wxBITMAP_TYPE_PNG  );
    bool bIsOK = wbmTest.IsOk();
    m_toolbarTemplate->AddTool(wxID_ANY, _("Add a row"), wbmTest, wxNullBitmap, wxITEM_NORMAL, _("Add/append a new row"), _("Add/append a new row"), NULL);
#else
    m_toolbarTemplate->AddTool(wxID_ANY, _("Add a row"), wxXmlResource::Get()->LoadBitmap(wxT("edit_add")), wxNullBitmap, wxITEM_NORMAL, _("Add/append a new row"), _("Add/append a new row"), NULL);

  .....
#endif
    m_toolbarTemplate->Realize();
The error comes when the last statement ->Realize() is executed, in the loop to display the button image, as soon as it tries to load the bit map, bmp.IsOK() fails.

The first clause, which loads the file directly, works, the code in the #else clause fails, even though they both load the same file.
And both files pass the test using pngcheck.
Win 10 64-bit, MSVC 2010/2015/2017, wxWidgets 3.1.0, CodeLite 12.0
Fight Spam, report it with wxSR

User avatar
eranif
CodeLite Plugin
Posts: 5898
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Tool bar icon problem

Post by eranif » Thu Nov 30, 2017 10:50 am

All images are embedded to your code using wxrc tool.
This is small utility provided by wxWidgets which converts the image into C code which can be then embedded into your binary without the need for providing additional resources when you distribute your code.
So if the image loading raises an error, then it's either wxWidgets bad conversion or maybe the image is badly formed
Make sure you have read the HOW TO POST thread

coder99
CodeLite Expert
Posts: 143
Joined: Wed Oct 22, 2008 6:50 am
Contact:

Re: Tool bar icon problem

Post by coder99 » Thu Nov 30, 2017 9:22 pm

Thank you, Eran.
I had thought that it was not some other software which was used to produce the code and your comments confirm that assumption.

Can you please indicate which wxrc options are used to produce the code so that I can try to work out manually where the problem might be.

I have meanwhile convinced myself that when the images are loaded the size ends up at 0,0 and thus the call to bmp.IsOK() fails
Win 10 64-bit, MSVC 2010/2015/2017, wxWidgets 3.1.0, CodeLite 12.0
Fight Spam, report it with wxSR

coder99
CodeLite Expert
Posts: 143
Joined: Wed Oct 22, 2008 6:50 am
Contact:

Re: Tool bar icon problem

Post by coder99 » Mon Dec 04, 2017 10:43 pm

By now, I think I have tracked down the issue and it very much looks like an issue in wxCrafter.

I have pared down my original project to the minimum (though it is still relatively large) that would show the issue and the problem seems to be that I have 2 identically named functions ( wxC9E31InitBitmapResources() ) intended to initialize the bitmap resources. As far as I can tell, these names are completely under wxCrafter's control and I have never manually edited any of the wxCrafter related/managed file directly.

All of the dialogs were created under wxCrafter, though at different times.
Output from MSVC 2015 search for "InitBitmapResources"

Code: Select all

Find all "InitBitmapResources", Subfolders, Find Results 2, Entire Solution, "*.c;*.cpp;*.cxx;*.cc;*.tli;*.tlh;*.h;*.hh;*.hpp;*.hxx;*.hh;*.inl;*.rc;*.resx;*.idl;*.asm;*.inc"
  D:\pkg\wx\MSVC2015\_3.1-2015\wxGtmTest2-fails\wxGtmBase_bitmaps.cpp(199):void wxCF0D5InitBitmapResources()
  D:\pkg\wx\MSVC2015\_3.1-2015\wxGtmTest2-fails\wxGtmBaseFrame.cpp(11):extern void wxCF0D5InitBitmapResources();
  D:\pkg\wx\MSVC2015\_3.1-2015\wxGtmTest2-fails\wxGtmBaseFrame.cpp(22):        wxCF0D5InitBitmapResources();
  D:\pkg\wx\MSVC2015\_3.1-2015\wxGtmTest2-fails\wxGtmDatabase\wxGtmDatabaseDlgsBase.cpp(11):extern void wxC9E31InitBitmapResources();   <<<<<<<<<<<<<
  D:\pkg\wx\MSVC2015\_3.1-2015\wxGtmTest2-fails\wxGtmDatabase\wxGtmDatabaseDlgsBase.cpp(22):        wxC9E31InitBitmapResources();
  D:\pkg\wx\MSVC2015\_3.1-2015\wxGtmTest2-fails\wxGtmDatabase\wxGtmDatabaseDlgsBase.cpp(84):        wxC9E31InitBitmapResources();
  D:\pkg\wx\MSVC2015\_3.1-2015\wxGtmTest2-fails\wxGtmDatabase\wxGtmDatabaseDlgsBase_bitmaps.cpp(34):void wxC9E31InitBitmapResources()
  D:\pkg\wx\MSVC2015\_3.1-2015\wxGtmTest2-fails\wxGTMTemplates\wxGtmTemplatesBaseDlg.cpp(11):extern void wxC9E31InitBitmapResources();   <<<<<<<<<<<<<<<<<<
  D:\pkg\wx\MSVC2015\_3.1-2015\wxGtmTest2-fails\wxGTMTemplates\wxGtmTemplatesBaseDlg.cpp(22):        wxC9E31InitBitmapResources();
  D:\pkg\wx\MSVC2015\_3.1-2015\wxGtmTest2-fails\wxGTMTemplates\wxGtmTemplatesBaseDlg_bitmaps.cpp(342):void wxC9E31InitBitmapResources()
  Matching lines: 10    Matching files: 6    Total files searched: 51
Because these functions are 'global', the second function in wxGtmTemplatesBaseDlg.cpp never gets executed ( and its presence in the code does not raise any flags) when the dialog is opened and instead the function in wxGtmDatabaseDlgsBase.cpp is executed and therefore any bitmaps defined in the templates dialog are never loaded and cause the errors I have been seeing.
If I rename one of the functions, the problem goes away because then the appropriate function is executed.
Win 10 64-bit, MSVC 2010/2015/2017, wxWidgets 3.1.0, CodeLite 12.0
Fight Spam, report it with wxSR

Post Reply