Crash in wxTextCtrl with hint

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
virious
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon May 08, 2017 7:51 pm
Location: Poland

Crash in wxTextCtrl with hint

Post by virious »

I have crash that happens when I use wxTextCtrl with hints. This is the callstack:

vcruntime140.dll!purecall+0x34
wxmsw31u_core_vc_x64_custom.dll!wxTextEntryHintData::RestoreTextColourIfNecessary+0x22 - d:\externals.dev\wxwidgets_v3_1_0\src\common\textentrycmn.cpp(109)
wxmsw31u_core_vc_x64_custom.dll!wxTextEntryHintData::OnSetFocus+0x42 - d:\externals.dev\wxwidgets_v3_1_0\src\common\textentrycmn.cpp(124)
wxbase31u_vc_x64_custom.dll!wxEvtHandler::SearchDynamicEventTable+0xfe - d:\externals.dev\wxwidgets_v3_1_0\src\common\event.cpp(1831)
wxbase31u_vc_x64_custom.dll!wxEvtHandler::TryHereOnly+0x22 - d:\externals.dev\wxwidgets_v3_1_0\src\common\event.cpp(1574)
wxbase31u_vc_x64_custom.dll!wxEvtHandler::ProcessEvent+0xe5 - d:\externals.dev\wxwidgets_v3_1_0\src\common\event.cpp(1484)
wxmsw31u_core_vc_x64_custom.dll!wxWindow::HandleSetFocus+0xcd - d:\externals.dev\wxwidgets_v3_1_0\src\msw\window.cpp(3978)
wxmsw31u_core_vc_x64_custom.dll!wxWindow::MSWHandleMessage+0x171 - d:\externals.dev\wxwidgets_v3_1_0\src\msw\window.cpp(2791)
wxmsw31u_core_vc_x64_custom.dll!wxTextCtrl::MSWHandleMessage+0x33 - d:\externals.dev\wxwidgets_v3_1_0\src\msw\textctrl.cpp(2067)
wxmsw31u_core_vc_x64_custom.dll!wxWindow::MSWWindowProc+0x38 - d:\externals.dev\wxwidgets_v3_1_0\src\msw\window.cpp(3524)
wxmsw31u_core_vc_x64_custom.dll!wxWndProc+0x9b - d:\externals.dev\wxwidgets_v3_1_0\src\msw\window.cpp(2668)

The scenario is that I have one wxTextCtrl. It has both text and hint set. Then I set empty text in code in text ctrl. Then I set some text again and when I click on the control, we have this crash.

I'm handling wxEVT_TEXT and wxEVT_CHAR_HOOK events but according to docs (http://docs.wxwidgets.org/trunk/classwx ... be83f1bed4), I'm using event.Skip(). I'm also using only ChangeValue() and SetValue() methods so this shouldn't be a problem. Do you have any ideas what I might be missing?

EDIT:
I tracked down that the issue happens when I use SetHint for empty string.
In

Code: Select all

bool wxTextEntryBase::SetHint(const wxString& hint)
{
    // Hint contents would be shown hidden in a password text entry anyhow, so
    // we just can't support hints in this case.
    if ( GetEditableWindow()->HasFlag(wxTE_PASSWORD) )
        return false;

    if ( !hint.empty() )
    {
        if ( !m_hintData )
            m_hintData = new wxTextEntryHintData(this, GetEditableWindow());

        m_hintData->SetHintString(hint);
    }
    else if ( m_hintData )
    {
        // Setting empty hint removes any currently set one.
        delete m_hintData;
        m_hintData = NULL;
    }
    //else: Setting empty hint when we don't have any doesn't do anything.

    return true;
}
it says that setting empty hint does nothing but for me it results in mentioned crash.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Crash in wxTextCtrl with hint

Post by doublemax »

Please try to create a minimal, compilable sample that shows the problem.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Crash in wxTextCtrl with hint

Post by ONEEYEMAN »

Hi,
Or try to reproduce the issue in the text sample.

Thank you.
Post Reply