#ifndef WX_PRECOMP
     #include "wx/event.h"
     #include "wx/window.h"
+    #include "wx/log.h"
 #endif //WX_PRECOMP
 
 #include "wx/thread.h"
 
             if ((j_evt.type & JS_EVENT_AXIS) && (j_evt.number < wxJS_MAX_AXES))
             {
+                // Ignore invalid axis.
+                if ( j_evt.number >= wxJS_MAX_AXES )
+                {
+                    wxLogDebug(wxS("Invalid axis index %d in joystick message."),
+                               j_evt.number);
+                    continue;
+                }
+
                 if (   (m_axe[j_evt.number] + m_threshold < j_evt.value)
                     || (m_axe[j_evt.number] - m_threshold > j_evt.value) )
             {