• 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 elenzil · Jun 04, 2016 at 02:04 AM · xcodecastingcompiler bug

hide your children, there's a float-to-ushort casting bug in the xcode 7.3.1 compiler

i'm super excited about this. i think it's a compiler bug.

check out this C# code:

 float val = -3.67;    // this value is not special, it's merely negative.
 ushort v1 = (ushort)val;
 ushort v2 = (ushort)(short)val;
 short  t3 = ( short)val;
 ushort v3 = (ushort)t3;

when compiled with xcode 7.3.1 the result when running on certain iOS devices is that v2 and v3 will be the expected value, 65533, but v1 will be 0.

have tested iPad3 and a handful of iPad Mini's & iPhone 5, and they all have the bug, whereas none of the iPhone 6's we've tested repro it.

also, if xcode 7.2.x is used to compile the project, the bug does not repro on any platform.

Comment
Add comment · Show 2
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 elenzil · Jun 04, 2016 at 02:19 AM 0
Share

wow, confirmed as an xcode bug.

a blank iOS project (not created from unity) repro's it with this code (which is what's generated by the C# --> cpp compiler):

 float val = -3.67f;
 uint16_t v1 = (((int32_t)((uint16_t)val)));    
 NSLog(@"the value is: %d", v1);

again specifically, on iPhone 6 the result is 65533 but on iPad 3 the result is 0.

avatar image elenzil · Jun 04, 2016 at 04:37 AM 0
Share

here's another simpler repro w/o unity:

 // when compiled in XCode 7.3.1,
 // the code below outputs the following on iPad3:
 // -4.0 -->     0, 65532
 
 // and this on iPhone6:
 // -4.0 --> 65532, 65532
 
 float fval = -4.0f;
 
 unsigned short us1 = (unsigned short)fval;
 unsigned short us2 = (unsigned short)(short)fval;
 NSLog(@"%5.1f --> %5d, %5d", fval, us1, us2);

according to stack overflow, casting a negative float to an unsigned short has undefined behavior in C. so i guess it's not technically a compiler bug.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

46 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

xcode view change from antialiased to aliased 0 Answers

Try Catch not working on xcode debug mode 0 Answers

how to fix the "unityexception : launching ios project via xcode failed" exception ? 0 Answers

huge iOS build size even with empty scene 0 Answers

ISN_GameCenterManager.mm - No matching function for call to 'UnitySendMessage' 0 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