Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by winxalex · Mar 14, 2015 at 01:16 AM · inputpluginsnative pluginosx

CFStringGetCharacters in Unity5.0 crash?

What was changed in U5.0???

The code was working in version U4.6 and when I update to U5.0.0.0f4:

Receiving unhandled NULL exception Launching bug reporter Obtained 46 stack frames. #0 0x007fff90e866d0 in __CFStrConvertBytesToUnicode #1 0x0000012f73c09e in (wrapper managed-to-native) ws.winx.platform.osx.Native:CFStringGetCharacters (intptr,ws.winx.platform.osx.Native/CFRange,intptr) + 0x10e (0x12f73bf90 0x12f73c0ea) [0x10d646330 - Unity Child Domain] #2 0x0000012f73bacb in ws.winx.platform.osx.Native/CFString:ToString () + 0x23b (0x12f73b890 0x12f73bc63) [0x10d646330 - Unity Child Domain] #3 0x0000012f739053 in ws.winx.platform.osx.OSXHIDInterface:HidDeviceAdded

https://github.com/winalex/Unity3d-InputMapper/blob/master/Assets/Scripts/ws/winx/platform/OSX/Native.cs

In Above function

 public override string ToString ()
             {
                 if(base.Value==null){
                 if (typeRef == IntPtr.Zero)
                     return null;
                 
                 string str;
                 int length = CFStringGetLength(typeRef);        
                 IntPtr u = CFStringGetCharactersPtr(typeRef);
                 IntPtr buffer = IntPtr.Zero;
                 if (u == IntPtr.Zero)
                 {
                     CFRange range = new CFRange(0, length);
                     buffer = Marshal.AllocCoTaskMem(length * 2);
                 --->    CFStringGetCharacters(typeRef, range, buffer);
                     u = buffer;
                 }
                 unsafe
                 {
                     str = new string((char*)u, 0, length);
                 }
                 if (buffer != IntPtr.Zero)
                     Marshal.FreeCoTaskMem(buffer);
                     base.Value=str;
                     return base.Value as String;
                 }else 
                     return base.Value as String;
             }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by iFischer_d · Oct 04, 2015 at 09:23 PM

I have been looking into this my self and it seems the crash is due to the fact that the supplied CFRange is expected to have it's "Length" and "Location" members defined as signed longs.

 internal struct CFRange
 {
     public long Location;
     public long Length;
     
     public CFRange(long l, long len)
     {
         Location = l;
         Length = len;
     }
 }

This requires a couple of spots, like "CFStringGetLength" or "LSGetApplicationForURL", etc. to return a long instead of an int.

And of course when making the new string, casting the long as an int (for safety you should check it for overflow first).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by winxalex · Oct 05, 2015 at 09:40 PM

Thx a lot. @iFischer_d It's really hard to develop for OSX cos of lack of docs. To develop using C# is even harder. And string manipulation from C++ to C# is one of the energy black holes.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Using C++ classes in native DLL for Unity 1 Answer

Do Native Mobile Plugins Require Pro? 1 Answer

Trouble with the xbox controller on Mac 0 Answers

Get key Tab not possible in OSX web player 0 Answers

OSX input dialog bug 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges