wxGetKeyState is crashing (wxMac)

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
acsMike
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Feb 11, 2005 9:05 am
Location: Stockholm, Sweden

wxGetKeyState is crashing (wxMac)

Post by acsMike » Tue Jan 30, 2007 2:38 pm

Hi,
I don't expect to find an answer to this problem, but thought it best to ask anyway, in case someone has actually stumbled upon it before.

On Mac I do several wxGetKeyState for several reasons. This works perfectly in most cases, but one beta tester is reporting that his program is crashing at that point. My findings indicate his keyboard (!) is making this happen.

This is the Apple crash log:

Code: Select all

Thread 0 Crashed:
0   com.apple.CoreFoundation       	0x907be088 CFStringGetLength + 52
1   ...connections.ReValverII_Live 	0x000be140 wxMacCFStringHolder::AsString(wxFontEncoding) + 48
2   ...connections.ReValverII_Live 	0x000d54d8 wxHIDDevice::Create(int, int, int) + 512
3   ...connections.ReValverII_Live 	0x000d5bd8 wxGetKeyState(wxKeyCode) + 84
4   ...connections.ReValverII_Live 	0x000565ac 
The users keyboard is a "Kinesis Advantage USB keyboard", and removing it makes the crash go away. This is a problem I can't fix, especially not remotely. Is there anything I can do on my end? I am using wxWidgets 2.6.3

Thanks! :-)
/Michael Ljunggren, developer
Peavey Electronics

Windows: 2.6.3, 2.8.9 (VS2005) ** Mac: 2.6.3 (XCode 3) ** WinCE: 2.8.9 (VS2005), ** GTK: 2.8.9 (Kdevelop)

protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol » Wed Jan 31, 2007 6:01 pm

Off the top of my head you can,
1.) reimplement wxGetKeyState using Carbon or Cocoa functions
2.) use a later version of wxWidgets, because the bug may have been fixed

best regards.

BTW: if you need help with option 1 let me know (i love cocoa/carbon programming).
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!

acsMike
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Feb 11, 2005 9:05 am
Location: Stockholm, Sweden

Post by acsMike » Wed Jan 31, 2007 6:05 pm

protocol wrote:Off the top of my head you can,
...
2.) use a later version of wxWidgets, because the bug may have been fixed
Hi, thanks for the suggestions. I am leaning towards a combination of 1 & 2. I can't switch to 2.8.0 because it breaks my apps in thousand pieces :-(
I hope I can use parts from 2.8.0 and build it into my current 2.6.3

Hmm... if it's too difficult, I'll get back to you to discuss your price?
/Michael Ljunggren, developer
Peavey Electronics

Windows: 2.6.3, 2.8.9 (VS2005) ** Mac: 2.6.3 (XCode 3) ** WinCE: 2.8.9 (VS2005), ** GTK: 2.8.9 (Kdevelop)

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Tue Feb 06, 2007 6:29 pm

> 1.) reimplement wxGetKeyState using Carbon or Cocoa functions

ROFL it is using carbon functions :D (well as close as there is) unless you want to go GetKeys() which isnt a bad idea. Back when this was done GetKeys() was bugged in OSX thus the HID implementation.

> 2.) use a later version of wxWidgets, because the bug may have been fixed

Yeah, try 2.8+ as there was a huge revamp done inbetween versions
[Mostly retired moderator, still check in to clean up some stuff]

acsMike
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Feb 11, 2005 9:05 am
Location: Stockholm, Sweden

Post by acsMike » Tue Feb 06, 2007 6:58 pm

Ryan Norton wrote: > 2.) use a later version of wxWidgets, because the bug may have been fixed

Yeah, try 2.8+ as there was a huge revamp done inbetween versions
Thanks Ryan. I appreciate hearing from you :-) Honestly, I can't see so many changes between 2.6.3 and 2.8 in terms of hid.cpp (?)

But let me specify. The crash occurs when getting the product name from the dictionary in wxHIDDevice::Create:

Code: Select all

        //Get [product] name
        CFStringRef cfsProduct = (CFStringRef)CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductKey));
        m_szProductName = wxMacCFStringHolder( cfsProduct, false ).AsString();
The 'wxMacCFStringHolder' crashes when returning the string as a wxString. I am completely unable to single step this or run it under a debugger as it only occur at one user.

The situation is such that 'CFDictionaryGetValue' appear to be returning "something" != NULL but I am not 100% sure it is a CFStringRef. That way, 'wxMacCFStringHolder' would crash, assuming it is a CFStringRef in the first place.

This user has a Kinesis USB keyboard. It has a built-in "hub", probably where he connects the mouse, possibly like the original Mac keyboard. Take a close look at the System Profile Dump:

Code: Select all

Kinesis Keyboard Hub:

  Version:	3.10
  Bus Power (mA):	500
  Speed:	Up to 12 Mb/sec
  Manufacturer:	PI Engineering
  Product ID:	0x0081
  Vendor ID:	0x05f3

        USB/PS2 Wheel Mouse:

          Version:	4.00
          Bus Power (mA):	100
          Speed:	Up to 1.5 Mb/sec
          Manufacturer:	Kensington
          Product ID:	0x1002
          Vendor ID:	0x047d

        USB Device:

          Version:	3.10
          Bus Power (mA):	124
          Speed:	Up to 12 Mb/sec
          Product ID:	0x0007
          Vendor ID:	0x05f3

The actual keyboard seem to be a sub device of his "hub".
/Michael Ljunggren, developer
Peavey Electronics

Windows: 2.6.3, 2.8.9 (VS2005) ** Mac: 2.6.3 (XCode 3) ** WinCE: 2.8.9 (VS2005), ** GTK: 2.8.9 (Kdevelop)

protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol » Tue Feb 06, 2007 7:55 pm

Ryan Norton wrote:> 1.) reimplement wxGetKeyState using Carbon or Cocoa functions

ROFL it is using carbon functions :D (well as close as there is) unless you want to go GetKeys() which isnt a bad idea. Back when this was done GetKeys() was bugged in OSX thus the HID implementation.
Also ROFL, my apologies. What I should have typed was: reimplement wxGetKeyState using your own/custom Carbon or Cocoa functions (and yes GetKeys() and GetCurrentKeyModifiers() would be used).
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Thu Feb 08, 2007 10:29 pm

[quote="acsMike]

The situation is such that 'CFDictionaryGetValue' appear to be returning "something" != NULL but I am not 100% sure it is a CFStringRef. That way, 'wxMacCFStringHolder' would crash, assuming it is a CFStringRef in the first place.
[/quote]

It appears wxMacCFStringHolder does NOT check the incoming CFString for NULL in 2.6 so that may be the issue...

Also, if you want to make sure it is a CFString type try something like

Code: Select all


if(CFGetTypeID(myObject) == CFStringGetTypeID())
//code
[/code]
[Mostly retired moderator, still check in to clean up some stuff]

acsMike
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Feb 11, 2005 9:05 am
Location: Stockholm, Sweden

Post by acsMike » Fri Feb 09, 2007 6:02 am

Ryan Norton wrote:
Also, if you want to make sure it is a CFString type try something like

Code: Select all


if(CFGetTypeID(myObject) == CFStringGetTypeID())
//code
Thank you Ryan. This can be helpful. I wish I could use 2.8 :?
/Michael Ljunggren, developer
Peavey Electronics

Windows: 2.6.3, 2.8.9 (VS2005) ** Mac: 2.6.3 (XCode 3) ** WinCE: 2.8.9 (VS2005), ** GTK: 2.8.9 (Kdevelop)

Post Reply