c# - How do i fix a Number Overflow with Monogame and Xamarin? -


i have installed latest versions of osx, xcode, , xamarin monotouch on development hardware, , cannot simplest monogame example run properly.

this bouncing box example, , crashes when application starts, on first initialization of color struct = 255:

public byte {     ...      set     {         this._packedvalue = (this._packedvalue & 0x00ffffff) | ((uint)(value << 24));     } } 

this code works fine on windows , ios simulator, when run on ipad 1 (ios 5) or iphone 5 (ios6), exception "system.overflowexception: number overflow.". if change code not cause overflow:

set {     var val = (uint)value;      var val2 = val << 24;      this._packedvalue = (this._packedvalue & 0x00ffffff) | val2; } 

this problem goes away, same problem exhibited r, g, , b properties well. intuition monogame wasn't written number overflow in mind, , there may countless examples of this. must 'new' problem since example code written.

is there compiler switch missing force ignore number overflows? using visual studio 2012 deploy on network, , under project properties not see settings relevant this.

if understand question , msdn documents, can whole operation inside unchecked block.

set {     unchecked     {         this._packedvalue = (this._packedvalue & 0x00ffffff) | ((uint)(value << 24));     } } 

however can result in unintended consequences (negative numbers, since you're using unsigned, i'm not sure if start @ 0 or still throws exception) , i've never used it.

reference can found here: http://msdn.microsoft.com/en-us/library/a569z7k8(v=vs.110).aspx


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -