MonoGame / MonoGame.Samples

A few cross-platform game samples using MonoGame.
www.monogame.net
Other
570 stars 298 forks source link

Missing Pericles font causes mysterious build failures #32

Closed AaronLS closed 9 years ago

AaronLS commented 9 years ago

Using the develop build of monogame(since it supports the new pipeline) along with the develop branch of the Samples, I was receiving build failures that only indicated MCGB.exe crashed with only an exit code as feedback.

I opened the Platformer project's *.mcgb file in MonoGame Pipeline and built it from there. There was an error about missing Pericles font. I hunted around the csproj XML, the Platform2d.mcgb, etc. and found no reference to Pericles. Finally I had the notion to open the Hud.spritefont, not knowing anything about the file format and reallizing it was a plaintext file. It had a reference to a font named Pericles.

This font did not exist on my system, and appears to be a Microsoft licensed font that allows redistribution. It is available here:

http://xbox.create.msdn.com/en-US/education/catalog/utility/font_pack

Once I downloaded and installed the fonts, I was able to complete the build with the Pipeline editor, and also build and run the Platformer sample.

Possible solutions: 1) Reference a font that is more reliable. 2) Include the *.ttf in the project since it appears to allow redistribution, and include readme advising it must be installed (usually simply double click the file). 3) If there is some way to reference font families instead of specific fonts, that might be slightly better, and even better also specify fallback font families. I.e. similar to how you would specify commonly installed font-family: Arial, Helvetica, sans-serif in CSS since different OS's will often name their helvetica type font differently due to copyrighted names, but essentially be the same font as far as size/kerning/serifs/etc. are concerned. 4) Advise upstream monogame to include the font. From what I read online it seems to imply that it was automatically installed with the XNA SDK. So perhaps monogame installer should continue this behavior. This however might lead to confusing issues for amateur developers who use the samples as a starting point, then deploy to other systems where the font doesn't exist, and have to discover the issue in the most difficult way, which is debugging a remote device. The transperancy/automation of this solution will make the developer less aware of the dependency on this font. For this reason this seems like a less desirable solution.

Having written this though and thinking through it more, perhaps some of my objections to 4 are are invalid, since I'm assuming once you perform the content compilation, then the end-user deployments don't need the original font. It is only needed during compilation I am guessing, and the resulting compiled font is what gets included in the output directory and deployed?

tomspilman commented 9 years ago

I was receiving build failures that only indicated MCGB.exe crashed with only an exit code as feedback.

It would be good to reproduce that crash. It should have given you a more clear error message like:

font.spritefont() - Error:  The font "Pericles" was not found!

That would have made things much easier to figure out.

Still... yea the samples need to include any custom fonts it uses.

AaronLS commented 9 years ago

@tomspilman Yes, I would think the same build output you see in the Pipeline editor when building there would be the same output in the VS output windows. I.e. MSGB.exe compile step would have its output piped to the VS output window. Maybe it would be appropriate to have verbose switches to limit output to warnings/error by default so as not to clutter the output.

tomspilman commented 9 years ago

Yes, I would think the same build output you see in the Pipeline editor when building there would be the same output in the VS output windows.

It should be. Are you saying you saw different output in VS than you saw in the Pipeline tool?

AaronLS commented 9 years ago

Correct. When the font was not installed on my computer, when building from VS, a "MGCB has stopped working" dialog appears and the error in the Error List is:

The command ""C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools\MGCB.exe" /@:"C:\Users\aaron\Downloads\MonoGame.Samples-develop\MonoGame.Samples-develop\Platformer2D\Content\Platformer2D.mgcb" /platform:WindowsGL /outputDir:"C:\Users\aaron\Downloads\MonoGame.Samples-develop\MonoGame.Samples-develop\Platformer2D\Platforms\WindowsGL\Content\bin\WindowsGL" /intermediateDir:"C:\Users\aaron\Downloads\MonoGame.Samples-develop\MonoGame.Samples-develop\Platformer2D\Platforms\WindowsGL\Content\obj\WindowsGL" /quiet" exited with code -532462766.

If I look at the build output there is an unhandled exception from MGCB:

1>  Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
1>  Parameter name: index
1>     at System.Collections.Generic.List`1.get_Item(Int32 index)
1>     at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.Texture2DWriter.Write(ContentWriter output, Texture2DContent value)
1>     at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentWriter.WriteObject[T](T value)
1>     at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.SpriteFontContentWriter.Write(ContentWriter output, SpriteFontContent value)
1>     at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentCompiler.Compile(Stream stream, Object content, TargetPlatform targetPlatform, GraphicsProfile targetProfile, Boolean compressContent, String rootDirectory, String referenceRelocationPath)
1>     at MonoGame.Framework.Content.Pipeline.Builder.PipelineManager.WriteXnb(Object content, PipelineBuildEvent pipelineEvent)
1>     at MonoGame.Framework.Content.Pipeline.Builder.PipelineManager.BuildContent(PipelineBuildEvent pipelineEvent, PipelineBuildEvent cachedEvent, String eventFilepath)
1>     at MonoGame.Framework.Content.Pipeline.Builder.PipelineManager.BuildContent(String sourceFilepath, String outputFilepath, String importerName, String processorName, OpaqueDataDictionary processorParameters)
1>     at MGCB.BuildContent.Build(Int32& successCount, Int32& errorCount)
1>     at MGCB.Program.Main(String[] args)
tomspilman commented 9 years ago

@AaronLS - Yea... that should have been handled a lot cleaner. A) the font processor should have failed when the font wasn't found B) the XNB writer should be capturing content building exceptions and reporting a good error message.

I'll see about correcting both of these in the pipeline code.

SimonDarksideJ commented 9 years ago

For now I've just submitted a PR to change the font used in the sample to Arial. #33 This ensures that all machines will be able to build the samples without extra stuff

theZMan commented 9 years ago

Simply shipping the font with the source code doesn't help as fonts need to be installed. So this should be shipped at part of MonoGame since that's what XNA 4.0 Game Studio did (note that 3.x did NOT - developers had to install it themselves)

I have no clue if the license Microsoft got with Ascender allows us to do that thugh - someone else would need to determine that http://xbox.create.msdn.com/en-US/education/catalog/utility/font_pack

Here's the spritefont schema http://msdn.microsoft.com/en-us/library/bb447759.aspx - it doesn't allow multiple fonts to be selected like CSS. Its pretty rare you would want that - fonts are so different in sizes that even a simple font switch can totally change the game layout.

Obviously the font processor needs a better error but installing the XNA font pack would be a much better solution if legally allowed.

tomspilman commented 9 years ago

it doesn't allow multiple fonts to be selected like CSS

Yea... you don't want the font selection to be fuzzy like that. It should always select the desired font or error out.

I think we support looking for the font TTF in the same folder as the .spritefont folder. That is as good as we can get I think without requiring users install the font into the system.

theZMan commented 9 years ago

Well that's a cool feature that XNA didn't do and would work well for samples since we can ship the TTF with the sample.

AaronLS commented 9 years ago

I think we support looking for the font TTF in the same folder as the .spritefont folder.

Nice. Side-by-side like this is really great because it makes it easy for others to get-latest and compile without interference from variations in their own local environment.

tomspilman commented 9 years ago

without interference from variations in their own local environment.

Yeah... that is exactly why we wanted that feature.

SimonDarksideJ commented 9 years ago

@AaronLS can you close this issue since it is no longer an issue?