ubuntu wxStaticText::SetLabel crashes

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

ubuntu wxStaticText::SetLabel crashes

Post by coderrc »

I am getting the goddamnedest error in my program under linux. When I try to call SetLabel on a static textbox the program crashes. The code runs perfectly under windows.

Any idea what I'm doing wrong?

wxwidgets 3.1
ubuntu 16

stack trace

Code: Select all

Thread 21 "wxApp" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffaf7fd700 (LWP 11713)]
malloc_consolidate (av=av@entry=0x7ffff1c95b00 <main_arena>) at malloc.c:4204
4204	malloc.c: No such file or directory.
(gdb) bt
#0  malloc_consolidate (av=av@entry=0x7ffff1c95b00 <main_arena>)
    at malloc.c:4204
#1  0x00007ffff1957d7f in _int_malloc (
    av=av@entry=0x7ffff1c95b00 <main_arena>, bytes=bytes@entry=2080)
    at malloc.c:3485
#2  0x00007ffff1958b8e in _int_memalign (
    av=av@entry=0x7ffff1c95b00 <main_arena>, alignment=alignment@entry=1024, 
    bytes=bytes@entry=1008) at malloc.c:4456
#3  0x00007ffff195cebd in _mid_memalign (address=<optimized out>, bytes=1008, 
    alignment=1024) at malloc.c:3155
#4  __posix_memalign (memptr=0x7fffaf7f94a0, alignment=<optimized out>, 
    size=1008) at malloc.c:5068
#5  0x00007fffee0f4c32 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#6  0x00007fffee0f58cb in g_slice_alloc ()
   from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#7  0x00007fffea9586b2 in ?? ()
   from /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0
#8  0x00007fffea959788 in ?? ()
   from /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0
#9  0x00007fffee89346e in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#10 0x00007fffee7ee4e3 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#11 0x00007fffee7f2534 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#12 0x00007fffee88eef3 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#13 0x00007fffee943f94 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#14 0x00007fffee9441df in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#15 0x00007fffee944297 in gtk_widget_get_preferred_width ()
   from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#16 0x00007fffee9445d0 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#17 0x00007ffff2bc8b18 in wxControl::GTKGetPreferredSize(_GtkWidget*) const ()
   from /usr/local/lib/libwx_gtk3u_core-3.1.so.0
#18 0x00007ffff2bc8baf in wxControl::DoGetBestSize() const ()
   from /usr/local/lib/libwx_gtk3u_core-3.1.so.0
#19 0x00007ffff2c06d65 in wxStaticText::DoGetBestSize() const ()
   from /usr/local/lib/libwx_gtk3u_core-3.1.so.0
#20 0x00007ffff2d5cd7e in wxWindowBase::GetBestSize() const ()
   from /usr/local/lib/libwx_gtk3u_core-3.1.so.0
#21 0x00007ffff2c073f6 in wxStaticText::GTKDoSetLabel(void (wxStaticText::*)(_GtkLabel*, wxString const&), wxString const&) ()
   from /usr/local/lib/libwx_gtk3u_core-3.1.so.0
#22 0x00007ffff2c074c1 in wxStaticText::SetLabel(wxString const&) ()
   from /usr/local/lib/libwx_gtk3u_core-3.1.so.0


the code that causes error

Code: Select all

wxString str = "";
		for (auto i : _strs) {
			wxString fmt= wxString::Format("%s%s\n", StaticObj::Instance()->m_public_text, i.to_string());
			str += fmt;
		}
		m_last5strs->SetLabelText(str);
		

the gui init

Code: Select all

void CDialogAccept::CreateControls()
{
	if (!wxXmlResource::Get()->LoadFrame(this, GetParent(), wxT("ID_D_DIALOG_ACCEPT")))
		wxLogError(wxT("Missing wxXmlResource::Get()->Load() in OnInit()?"));
	m_lbldrawing = XRCCTRL(*this, "ID_C_STATUS_2", wxStaticText);
	m_last5str = XRCCTRL(*this, "ID_C_STATUS_4", wxStaticText);
}
the XRC

Code: Select all

<object class="wxFrame" name="ID_D_DIALOG_ACCEPT" subclass="CDialogAccept">
        <style>wxNO_BORDER</style>
        <exstyle>wxWS_EX_BLOCK_EVENTS</exstyle>
        <bg>#0000FF</bg>
        <size>469,319</size>
        <title>OPERATOR MONEY__ACCEPT</title>
        <centered>1</centered>
        <object class="wxBoxSizer">
            <orient>wxVERTICAL</orient>
            <object class="sizeritem">
                <flag>wxGROW|wxLEFT|wxRIGHT</flag>
                <border>10</border>
                <object class="CMenuHeader" name="ID_PANEL_TITLE">
                    <size>-1,50</size>
                    <style>wxNO_BORDER</style>
                    <exstyle>wxWS_EX_VALIDATE_RECURSIVELY</exstyle>
                    <bg>#0000FF</bg>
                    <hasPaging>1</hasPaging>
                    <m_PageTitle>ACCEPT</m_PageTitle>
                </object>
            </object>
            <object class="sizeritem">
                <flag>wxGROW|wxLEFT|wxRIGHT</flag>
                <border>10</border>
                <option>11</option>
                <object class="wxPanel" name="ID_PANEL_BODY">
                    <font>
                        <size>12</size>
                        <family>swiss</family>
                        <weight>bold</weight>
                        <face>Arial</face>
                    </font>
                    <style>wxNO_BORDER|wxTAB_TRAVERSAL</style>
                    <exstyle>wxWS_EX_VALIDATE_RECURSIVELY</exstyle>
                    <bg>#000000</bg>
                    <object class="wxBoxSizer">
                        <orient>wxVERTICAL</orient>
                        <object class="sizeritem">
                            <flag>wxGROW|wxALL</flag>
                            <border>10</border>
                            <object class="wxPanel" name="ID_PANEL">
                                <style>wxNO_BORDER|wxTAB_TRAVERSAL</style>
                                <exstyle>wxWS_EX_VALIDATE_RECURSIVELY</exstyle>
                                <object class="wxBoxSizer">
                                    <orient>wxHORIZONTAL</orient>
                                    <object class="sizeritem">
                                        <flag>wxALIGN_CENTER_VERTICAL|wxFIXED_MINSIZE</flag>
                                        <border>30</border>
                                        <object class="wxStaticText" name="ID_C_STATUS_1">
                                            <size>100,-1</size>
                                            <font>
                                                <size>14</size>
                                                <family>swiss</family>
                                                <weight>bold</weight>
                                                <face>Arial</face>
                                            </font>
                                            <style>wxST_NO_AUTORESIZE|wxNO_BORDER</style>
                                            <fg>#00FF00</fg>
                                            <label>SLOT #1</label>
                                        </object>
                                    </object>
                                    <object class="sizeritem">
                                        <flag>wxGROW|wxLEFT</flag>
                                        <border>10</border>
                                        <object class="wxStaticText" name="ID_C_STATUS_2">
                                            <size>360,30</size>
                                            <style>wxNO_BORDER</style>
                                            <label></label>
                                        </object>
                                    </object>
                                    <object class="spacer">
                                        <flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
                                        <border>5</border>
                                        <option>1</option>
                                        <size>5,5</size>
                                    </object>
                                </object>
                            </object>
                        </object>
                        <object class="sizeritem">
                            <flag>wxGROW|wxLEFT</flag>
                            <border>25</border>
                            <object class="wxStaticText" name="ID_C_STATUS_3">
                                <font>
                                    <size>16</size>
                                    <family>swiss</family>
                                    <weight>bold</weight>
                                    <face>Arial</face>
                                </font>
                                <style>wxNO_BORDER</style>
                                <fg>#00FF00</fg>
                                <label>LAST 5 BILLS</label>
                            </object>
                        </object>
                        <object class="sizeritem">
                            <flag>wxGROW|wxLEFT|wxRIGHT</flag>
                            <border>25</border>
                            <object class="wxStaticText" name="ID_C_STATUS_4">
                                <font>
                                    <size>16</size>
                                    <family>swiss</family>
                                    <weight>bold</weight>
                                    <face>Arial</face>
                                </font>
                                <style>wxNO_BORDER</style>
                                <fg>#FFFFFF</fg>
                                <label></label>
                            </object>
                        </object>
                    </object>
                </object>
            </object>
        </object>
    </object>
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: ubuntu wxStaticText::SetLabel crashes

Post by DavidHart »

Hi,

I suspect something is losing scope and its memory recycled, which seems to happen faster in Linux than in Windows. e.g. it's a known problem with the temporary wxCharBuffer pointer returned by wxString::mb_str(). As a test, try replacing your current code with m_last5strs->SetLabelText("Foo");

What is the type of _strs? What does i.to_string() return?

Regards,

David
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: ubuntu wxStaticText::SetLabel crashes

Post by coderrc »

_strs is a boost::circular_buffer
i.to_string() returns std::__cxx11::wstring
StaticObj::Instance()->m_public_text is a std::__cxx11::wstring

"foo" works.
variables fmt and str both print correctly to std out, so the strings are still in scope immediately preceding the call to SetLabelText which then crashes
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: ubuntu wxStaticText::SetLabel crashes

Post by DavidHart »

I see. Various suggestions:
Try doing:
  • 1) str << fmt.c_str();
    If that's no better,
    2)wxString fmt(i.to_string()); str << fmt;
    and if that works, whatever is the substitute for wxString::Format("%s\n", StaticObj::Instance()->m_public_text);
    Finally, the nuclear option:
    3) Run your program in valgrind. =D>
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: ubuntu wxStaticText::SetLabel crashes

Post by PB »

I have never really used XRC so I cannot tell if the code is correct.

Anyway ... Are you sure that m_last5str is a valid instance of wxStaticText. Can you successfully call a member function that accesses some wxStaticText specific member variable or at least successfully retrieve its current label via GetLabelText()?
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: ubuntu wxStaticText::SetLabel crashes

Post by coderrc »

@PB I doubt that's the issue since it works on windows and sometimes on some linuxes. But I suppose I can always give it a go.

it now seems to run correctly when run with gdb or valgrind. but crashes without it. 5 inches forward and 6 inches back... /wrists

ETA:: adding wxST_NO_AUTORESIZE to the xrc seems to have put a bandaid over the problem quite nicely. :| I wish I knew what the root issue was though, in case the bandaid ever falls off.
Post Reply