#15256 closed defect (fixed)

wxCocoa HitTest in wxNotebook crashes

Reported by: bartvanstiphout Owned by:
Priority: normal Milestone:
Component: wxOSX-Cocoa Version:
Keywords: HitTest wxNotebook wxCocoa Cc:
Blocked By: Blocking:
Patch: no

Description

When using the wxNotebook HitTest function, the app crashes.

If I disable the following lines it works perfectly, but I don't know why.

    int TabHitTest(const wxPoint & pt, long* flags)
    {
        int retval = wxNOT_FOUND;
        
        NSPoint nspt = wxToNSPoint( m_osxView, pt );
        
        wxNSTabView* slf = (wxNSTabView*) m_osxView;
        
        NSTabViewItem* hitItem = [slf tabViewItemAtPoint:nspt];
        
        if (!hitItem) {
//            *flags = wxBK_HITTEST_NOWHERE;
        } else {
            retval = [slf indexOfTabViewItem:hitItem];
//            *flags = wxBK_HITTEST_ONLABEL;
        }
        
        return retval; 
    }

Change History (4)

comment:1 follow-up: Changed 17 months ago by vadz

  • Status changed from new to infoneeded_new

Err, perhaps you pass it a bad flags pointer?

Does the problem happen in the notebook sample if you press Cmd+H in it (or select the corresponding command from the menu)?

comment:2 in reply to: ↑ 1 Changed 17 months ago by bartvanstiphout

  • Status changed from infoneeded_new to new

Replying to vadz:

Err, perhaps you pass it a bad flags pointer?

Does the problem happen in the notebook sample if you press Cmd+H in it (or select the corresponding command from the menu)?

I only pass the position. The flags then are defaulted to NULL

int testResult = HitTest(event.GetPosition());

I guess thats where it goes wrong, because there is no check for that parameter to be NULL. It should be though, since it is the default value.

comment:3 Changed 17 months ago by ericj

How do you connect the event handler? This smells like it could be a problem with wrong/missing "event sink" parameter to a Connect() call.

If you're using wx 2.9.x (which you should in any case under OSX), use Bind() instead of Connect(), because it will create a compiler error if you did something wrong.

comment:4 Changed 17 months ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [74238]) Handle NULL flags argument in wxOSX wxNotebook::HitTest().

Don't crash if flags are not specified, this parameter is optional.

Closes #15256.

Note: See TracTickets for help on using tickets.