Guido Van Hoecke <gui...@gmail.com> writes:

> Following method crashes on iPad.

The problem might be related to the size of the font. The same code
works fine on iphone, but of course uses a smaller fint there. (The game
draws a character in an 8x8 grid, which means cell size and thus font
size is much smaller on iphone)

Guido

>
>     private void DrawChar (CGContext g, RectangleF frame, string c, StateType 
> state)
>     {
>       var h = Convert.ToInt32 (frame.Height * .8);
>       var s = new NSString (c);
>       var size = MCiOS.TextSize (UIFont.BoldSystemFontOfSize (h), c.ToString 
> ());
>       var p = new PointF (frame.X + (frame.Width - size.Width) / 2, frame.Y + 
> (frame.Height - size.Height) / 2);
>       var font = UIFont.BoldSystemFontOfSize(h);
>       Debug.Assert(font != null, "Failed to get font of size " + h);
>       s.DrawString (p, new UIStringAttributes {
>         Font = font,
>         ForegroundColor = _textColors [(int)state],
>       });
>     }
>
> The 'Font = font' line is painted green.
>
> Initially I did not use the intermediate variable but changed the code
> so that I could check on the font being null. Turns out it isn't: I get
> {Helvetica-Bold 56}. 
>
> The details of the exception seem to indicate that it really crashes
> inside MonoTouch:
>
> System.ArgumentNullException: Argument cannot be null.
> Parameter name: key
>   at MonoTouch.Foundation.DictionaryContainer.SetNativeValue 
> (MonoTouch.Foundation.NSString key, INativeObject value, Boolean 
> removeNullValue) [0x0002f] in 
> /Developer/MonoTouch/Source/maccore/src/Foundation/.pmcs-compat.DictionaryContainer.cs:343
>   at MonoTouch.UIKit.UIStringAttributes.set_Font (MonoTouch.UIKit.UIFont 
> value) [0x00000] in 
> /Developer/MonoTouch/Source/monotouch/src/UIKit/.pmcs-compat.UIStringAttributes.cs:78
>   at XOOX.Classes.PuzzleView.DrawChar (MonoTouch.CoreGraphics.CGContext g, 
> RectangleF frame, System.String c, StateType state) [0x000ad] in 
> /Users/guivho/Mono/XOOX/XOOX/Classes/PuzzleView.cs:332
>   at XOOX.Classes.PuzzleView.DrawCell (RectangleF frame, System.String c, 
> TrailType trail, StateType state, System.Collections.Generic.List`1 dots) 
> [0x00066] in /Users/guivho/Mono/XOOX/XOOX/Classes/PuzzleView.cs:294
>   at XOOX.Classes.PuzzleView.DrawPuzzle () [0x00163] in 
> /Users/guivho/Mono/XOOX/XOOX/Classes/PuzzleView.cs:163
>   at XOOX.Classes.PuzzleView.Draw (RectangleF rect) [0x00002] in 
> /Users/guivho/Mono/XOOX/XOOX/Classes/PuzzleView.cs:112
>   at at (wrapper managed-to-native) 
> MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
>   at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String 
> principalClassName, System.String delegateClassName) [0x0004c] in 
> /Developer/MonoTouch/Source/monotouch/src/UIKit/.pmcs-compat.UIApplication.cs:38
>   at XOOX.Application.Main (System.String[] args) [0x00008] in 
> /Users/guivho/Mono/XOOX/XOOX/Main.cs:15
>
> Is there some way I can prevent this error from happening?
>
>
> Guido
>
> --
> The way I understand it, the Russians are sort of a combination of evil and
> incompetence... sort of like the Post Office with tanks.
>               -- Emo Philips
_______________________________________________
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to