Update to ASSERT using String.Concat( )

To anyone that cares…

I restructured my code and I still could not get String.Concat() to work. I even tried Concat in a new thread.

However, a simple for loop did the thick! (I was going to use a loop in the first place)

Updated code that worked. At the end of the code you can see the string I wanted.



using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp1
{
    public partial class Program
    {
        Bitmap TBitmap;
        Text text;
        Text textS;
        
        char[] NinaBfont;
        string[] parts;

        void ProgramStarted()
        {
            Debug.Print("Program Started");

            TBitmap = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
            Font myFont = Resources.GetFont(Resources.FontResources.NinaB);

            text = new Text();
            textS = new Text();
            // Set Font
            text.Font = Resources.GetFont(Resources.FontResources.NinaB);
            textS.Font = Resources.GetFont(Resources.FontResources.small);
            NinaBfont = new char[130];
            parts = new string[130];

            beginhere();
        }

        void beginhere()
        {
            //Do not allow code to run until button is pressed
            //This is because of ***ASSERT*** when using string result = String.Concat(parts);

            while(!button.IsPressed)
            {
                Debug.Print("CANNOT RUN - SAFETY CHECK");
                if (button.IsPressed)
                {
                    break;
                }
            }

            Debug.Print("RUNNING - SAFETY CHECK");
            uint x = 2;
            uint y = 0;
            uint W = 0;
            uint H = 0;
            string part;

            y += (uint)text.Font.Height + 3;
            x = 2;

            for (ushort i = 0; i <= 128; ++i)
            {
                char T = Convert.ToChar(i); 
                W = (uint) text.Font.CharWidth(T);
                H = (uint)text.Font.Height;
                NinaBfont[i] = T;

                part = String.Empty;
                part = T.ToString();
                parts[i] = part;
                x += (W + 2);
                
                if(x > 300)
                {
                    x = 2;
                    y+= (H + 2);
                }
            }
            
            //Added thread for a test
            Thread thread = new Thread(new ThreadStart(generateString));
            thread.Start();
            thread.Abort();

            /*
            x = 2;
            y += 24;

            char[] smallFont = new char[129];

            for (ushort i = 0; i <= 128; ++i)
            {
                char T = Convert.ToChar(i);
                W = (uint)textS.Font.CharWidth(T);
                H = (uint)textS.Font.Height;
                smallFont[i] = T;

                display_T35.SimpleGraphics.DisplayText(T.ToString(), textS.Font, GT.Color.White, x, y);
                x += (W + 2);

                if (x > 300)
                {
                    x = 2;
                    y += (H + 2);
                }
            }
            */
        }
        //

        private void generateString()
        {
            string result = String.Empty;

            for (uint i = 0; i <= 128; ++i)
            {
                result += parts[i];
            }
            
            // result = String.Concat(parts); Fails with *****ABORT*****
            
            // The for loop returns the string I wanted
            // "\a\b\t\n\v\f\re !\"#$%&'()*+,-./0123456789:;<=>?@ ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~€"
        }
        
    } //end class
} //end namespace

Bye!


If you can try a simple program, like 10 lines of code and can show this happening then we can provide bug report to Microsoft.

Gus

I can take out some of the code but if I remove my ‘safety’ button I am afraid that i’ll be back into a ‘bricked’ Spider. REALLY, I had an awful time getting it working again.

I’ll post something with the button if that is OK? You folks can take it out!

2 more lines for a button would be no problem

GUS

I’ll post the shortest code I have that will still read the font contents to make a string from.
I’m sure your guys/gals could compress it a bit more than I ever could.
No pro programmer here…

I’m also sure you could get the spider running again faster than I can if you remove the ‘safety button’ code.

I just ran the following and received the ASSERT in the T35 display
Using a the T35 and a button (Socket 4) on the Fez.Spider

NOTE: I just found something!

I was looking on MSDN while writing this post and found the following.

The String class does not currently support strings with null characters (the ‘\0’ character) in them. This behavior is different from the .NET Framework for Windows.

The first char[0] the font contain null. char[0] is \0 that I believe is null.

Oh well, at least we know why now!



using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;

namespace TinyFontTest
{
    public partial class Program
    {
        Bitmap TBitmap;
        Text text;    
        char[] NinaBfont;
        string[] parts;

        void ProgramStarted()
        {
            TBitmap = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
            Font myFont = Resources.GetFont(Resources.FontResources.NinaB);
            text = new Text();
            text.Font = Resources.GetFont(Resources.FontResources.NinaB);
            NinaBfont = new char[130]; //Few more than needed
            parts = new string[130];

            beginhere();
        }

        void beginhere()
        {
            //Remove at your own risk
            while(!button.IsPressed)
            {
                Debug.Print("Press button to begin - SAFETY CHECK");
                if (button.IsPressed)
                {
                    break;
                }
            }

            uint W = 0;
            uint H = 0;
            string part;

            for (ushort i = 0; i <= 128; ++i)
            {
                char T = Convert.ToChar(i); 
                W = (uint) text.Font.CharWidth(T);
                H = (uint)text.Font.Height;
                NinaBfont[i] = T;

                part = String.Empty;
                part = T.ToString();
                parts[i] = part;
            }

            string result = String.Empty;
            result = String.Concat(parts);
        }
        //

        // A for loop returns the string I wanted
        // "\a\b\t\n\v\f\re !\"#$%&'()*+,-./0123456789:;<=>?@ ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~€"
        
    } //end class
} //end namespace