1
\$\begingroup\$

I Try to use my ContentProcessor, which I wrote on a Linux machine, on a Mac but it crashes with an unexpected failure.

The Pipeline Tool gives me the following
enter image description here

It seems to be a problem with the FontDescription class. In the constructor of my FontDescription class, I create a file if it does not exist. The File is never created, so I assume that the line is never called and the problem is in the base constructor. Since I couldn't find anyone else with this problem I must assume that I am doing something wrong.

My classes look as follows:

using System;
using System.IO;
using System.Xml;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;

namespace CH.LocalisationPipeline
{
    [ContentProcessor(DisplayName = "LocalizedFontProcessor of CH")]
    public class LocalisedFontProcessor : ContentProcessor<LocalisedFontDescription, SpriteFontContent>
    {
        public override SpriteFontContent Process(LocalisedFontDescription input, ContentProcessorContext context)
        {
            SpriteFontContent returnValue = null;
            if (!File.Exists(@"outputPipeLine.txt"))
            {
                File.Create(@"outputPipeLine.txt");
            }
            else
            {
                File.AppendAllText(@"outputPipeLine.txt", Environment.NewLine);
            }
            try
            {
                GetLocalisedResx(input, context);
                File.AppendAllText(@"outputPipeLine.txt", "Input is null? "+(input==null).ToString()+ Environment.NewLine);
                File.AppendAllText(@"outputPipeLine.txt", " " + Environment.NewLine+"INPUT:   " + input + Environment.NewLine + Environment.NewLine);
                returnValue = context.Convert<FontDescription, SpriteFontContent>(input, "FontDescriptionProcessor");
            }
            catch (Exception ex)
            {
                File.AppendAllText(@"outputPipeLine.txt", ex.Message+" "+ex.StackTrace+ Environment.NewLine);
                throw;
            }

            return returnValue;
        }

        private static void GetLocalisedResx(LocalisedFontDescription input, ContentProcessorContext context) 
        {
            foreach (String resourceFile in input.ResourceFiles)
            {
                String absolutPath = Path.GetFullPath(resourceFile);
                if (File.Exists(absolutPath))
                {
                    ReadResource(input, absolutPath);
                    context.AddDependency(absolutPath);
                }
                else
                {
                    File.AppendAllText(@"outputPipeLine.txt", "File doesnt exists "+absolutPath+ Environment.NewLine);
                }
            }
            foreach (String stringsXml in input.StringsXML)
            {
                String absolutPath = Path.GetFullPath(stringsXml);
                if (File.Exists(absolutPath))
                {
                    ReadStrings(input, absolutPath);
                    context.AddDependency(absolutPath);
                }
                else
                {
                    File.AppendAllText(@"outputPipeLine.txt", "File doesnt exists " + absolutPath+ Environment.NewLine);
                }
            }
        }

        private static void ReadResource(LocalisedFontDescription input, String absolutPath)
        {
            input.Characters.Add('a');
            return;

            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(absolutPath);

            foreach (XmlNode xmlNode in xmlDocument.SelectNodes("root/data/value"))
            {
                String resourceString = xmlNode.InnerText;
                foreach (char usedCharacter in resourceString)
                {
                    input.Characters.Add(usedCharacter);
                    File.AppendAllText(@"outputPipeLine.txt", usedCharacter + " ");
                }
            }
            File.AppendAllText(@"outputPipeLine.txt", Environment.NewLine);
        }

        private static void ReadStrings(LocalisedFontDescription input, String absolutPath)
        {
            input.Characters.Add('a');
            return;

            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(absolutPath);

            foreach (XmlNode xmlNode in xmlDocument.SelectNodes("resources/string"))
            {
                String resourceString = xmlNode.InnerText;
                foreach (char usedCharacter in resourceString)
                {
                    input.Characters.Add(usedCharacter);
                    File.AppendAllText(@"outputPipeLine.txt", usedCharacter+" ");
                }
            }
            File.AppendAllText(@"outputPipeLine.txt", Environment.NewLine);
        }
    }
}

and

 using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;

namespace CH.LocalisationPipeline
{
    public class LocalisedFontDescription : FontDescription
    {

        public LocalisedFontDescription() : base("Arial",14,1)
        {
            if (!File.Exists(@"outputPipeLine.txt"))
            {
                File.Create(@"outputPipeLine.txt");
            }
        }

        [ContentSerializer(Optional=true, CollectionItemName="Resx")]
        public List<String> ResourceFiles 
        { 
            get; 
            private set; 
        }

        [ContentSerializer(Optional = true, CollectionItemName = "xml")]
        public List<String> StringsXML
        {
            get 
            {
                List<String> returnValue = new List<string>();
                try
                { 
                    String cwd = System.IO.Directory.GetCurrentDirectory();
                    var workingDir = new System.IO.DirectoryInfo(cwd);
                    var resourcesDir = System.IO.Path.Combine(workingDir.Parent.FullName, "Resources");
                    if (!System.IO.Directory.Exists(resourcesDir)) 
                    {
                        return returnValue;
                    }

                    var resources = new System.IO.DirectoryInfo(resourcesDir);
                    foreach (var subDir in resources.GetDirectories())
                    {
                        if (subDir.Name.StartsWith("Values")) 
                        {
                            foreach (var item in subDir.GetFiles())
                            {
                                if (item.Name.StartsWith("Strings")) 
                                {
                                    returnValue.Add(item.FullName);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    File.AppendAllText(@"outputPipeLine.txt", ex.Message + " " + ex.StackTrace + Environment.NewLine);
                    throw;
                }
                return returnValue;
            }
            private set 
            {
                ;
            }
        }

    }
}

From Rider and Visual Studio2019 I get the following message

LabelText.spritefont: [] Importer 'FontDescriptionImporter' had unexpected failure!

the spritefont is this

<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
  <Asset Type="CH.LocalisationPipeline.LocalisedFontDescription">

    <!--
    Modify this string to change the font that will be imported.
    -->
    <FontName>Fipps</FontName>

    <!--
    Size is a float value, measured in points. Modify this value to change
    the size of the font.
    -->
    <Size>10</Size>

    <!--
    Spacing is a float value, measured in pixels. Modify this value to change
    the amount of spacing in between characters.
    -->
    <Spacing>0</Spacing>

    <!--
    UseKerning controls the layout of the font. If this value is true, kerning information
    will be used when placing characters.
    -->
    <UseKerning>true</UseKerning>

    <!--
    Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
    and "Bold, Italic", and are case sensitive.
    -->
    <Style>Regular</Style>

    <!--
    If you uncomment this line, the default character will be substituted if you draw
    or measure text that contains characters which were not included in the font.
    -->
    <!-- <DefaultCharacter>*</DefaultCharacter> -->

    <!--
    CharacterRegions control what letters are available in the font. Every
    character from Start to End will be built and made available for drawing. The
    default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
    character set. The characters are ordered according to the Unicode standard.
    See the documentation for more information.
    -->
    <CharacterRegions>
      <CharacterRegion>
        <Start>&#32;</Start>
        <End>&#126;</End>
      </CharacterRegion>
    </CharacterRegions>

    <ResourceFiles>
      <Resx>../Properties/Resources.resx</Resx>
      <Resx>../Properties/Resources.de-DE.resx</Resx>
    </ResourceFiles>
  </Asset>
</XnaContent>

How can I resolve this issue? I tried it with MonoGame 3.6 and 3.7.1, with both I wasn't able to process my files. I tried it with a simple character 'a' to be sure that it isn't a problem of my files but the files were read correctly.

\$\endgroup\$
2
\$\begingroup\$

At this time and with that error ... you should post this as a issue on github for monogame which is probably the correct place and maybe the only place to get attention from someone capable of giving a answer to this question.

https://github.com/MonoGame/MonoGame/issues Follow the instructions on the issue submission, if possible make a simplified example to go along with the issue. There are lots of people contributing and lots of work is being done all the time but no one gets paid to create monogame it is completely open source. In many ways it still isn't quite up to par with xna and in many ways it has completely surpassed it.

I would post this as a comment as it is not a true answer. However i am denied that option due to lack of reputation. This is ironic as one would think comments would be for people who open new accounts, not answers.

Regardless i believe this is the correct answer atm. Beyond a useless short obvious answer that will be of no real help.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.