• Advertisement
Sign in to follow this  

XNA - Problems With ContentManager

This topic is 2084 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So i am mucking around with the Farseer Physics Engine and XNA. I'm running into issues loading content.

DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);

When this code is run, i get "Error loading "font". File not found."

How should i fix this? I assume that ScreenManager.Content is empty or something and it's attempting to load a font that doesn't exist or something since it is attempting to load a file using an invalid directory.

Share this post


Link to post
Share on other sites
Advertisement
That's not a lot of code to go on, can we see what DebugView.LoadContent looks like?

Some quick googling turned up one potential lead...

Does the path string to "font" include "@Content/" at the beginning?

Share this post


Link to post
Share on other sites
Sorry for the lack of details.

if (DebugView == null)
            {
                DebugView = new DebugViewXNA(World);
                DebugView.RemoveFlags(DebugViewFlags.Shape);
                DebugView.RemoveFlags(DebugViewFlags.Joint);
                DebugView.DefaultShapeColor = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
                DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);
            }


The real problem here is that ScreenManager.Content is having invalid fonts added to it for some reason. DebugView.LoadContent is simply trying to load the fonts and is running into an errant filepath.

Error loading "font". File not found.

"font" should be an actual filepath such as "Fonts/someFontName.spritefont". I don't know what part of my code is adding this errant filepath to the ContentManager.

Share this post


Link to post
Share on other sites

Sorry for the lack of details.
(code snippet)

You went the wrong direction in providing extra code :) Can you show the actual LoadContent function for DebugView, and not the code surrounding the function call?

"font" should be an actual filepath such as "Fonts/someFontName.spritefont"

So perhaps try adding "@Content/" to the beginning of said filepath?

I don't know what part of my code is adding this errant filepath to the ContentManager.

That I couldn't tell you unless I saw your entire codebase. But if you're writing it, and you don't know where fonts paths are being defined, that's a problem in itself.

Share this post


Link to post
Share on other sites

[quote name='twoski' timestamp='1338915517' post='4946508']
Sorry for the lack of details.
(code snippet)

You went the wrong direction in providing extra code :)  Can you show the actual LoadContent function for DebugView, and not the code surrounding the function call?

"font" should be an actual filepath such as "Fonts/someFontName.spritefont"

So perhaps try adding "@Content/" to the beginning of said filepath?

I don't know what part of my code is adding this errant filepath to the ContentManager.

That I couldn't tell you unless I saw your entire codebase.  But if you're writing it, and you don't know where fonts paths are being defined, that's a problem in itself.
[/quote]

I don't have the code for DebugView's LoadContent function since it's closed source afaik. It's a debugger thing for Farseer Physics.public void LoadContent(GraphicsDevice device, ContentManager content);That's the interface i have to work with. I'm just confused by this error because there is only one place in all of my code where i am loading fonts, and this code should work fine since it's done this way in functional examples:public class SpriteFonts    {        public SpriteFont DetailsFont;        public SpriteFont FrameRateCounterFont;        public SpriteFont MenuSpriteFont;        public SpriteFonts(ContentManager contentManager)        {            FrameRateCounterFont = contentManager.Load("Fonts/frameRateCounterFont");            DetailsFont = contentManager.Load("Fonts/detailsFont");            MenuSpriteFont = contentManager.Load("Fonts/menuFont");        }    }I'm kind of new to C#/XNA in general, sorry for the lacking descriptiveness.

Share this post


Link to post
Share on other sites
I would recommend using the the source lang="csharp" BB code, because otherwise, the formatting will end up like your above post which makes it very difficult to read. Do you have the fonts in the interface added to the content pipeline within the Fonts folder?

Share this post


Link to post
Share on other sites

I would recommend using the the source lang="csharp" BB code, because otherwise, the formatting will end up like your above post which makes it very difficult to read. Do you have the fonts in the interface added to the content pipeline within the Fonts folder?


All 3 of the fonts i am using are a part of my content project - my program actually loads and displays the menu correctly.
http://i.imgur.com/7KjGo.jpg
As soon as i load my test environment (a simple cube controlled by user input) it errors out when the test loads its content.

Share this post


Link to post
Share on other sites
Are you loading or drawing using SpriteFonts in your test environment? If so, can we see the code that loads those fonts?

Share this post


Link to post
Share on other sites
Here's the offending method (for the record, farseer isn't closed-source, I pulled this off their codeplex source repo):

public void LoadContent(GraphicsDevice device, ContentManager content)
{
// Create a new SpriteBatch, which can be used to draw textures.
_device = device;
_batch = new SpriteBatch(_device);
_primitiveBatch = new PrimitiveBatch(_device, 1000);
_font = content.Load<SpriteFont>("font");
_stringData = new List<StringData>();
_localProjection = Matrix.CreateOrthographicOffCenter(0f, _device.Viewport.Width, _device.Viewport.Height,
0f, 0f, 1f);
_localView = Matrix.Identity;
}


Are any of your fonts named "font" in your content folder? If none of the projects have an associated resource with a friendly name of "font", this will choke.

Share this post


Link to post
Share on other sites
Here is the code used in my test:

http://pastebin.com/4qqXYLcm

The only part that has to do with fonts would be base.LoadContent(), which is derived from another class, PhysicsGameScreen. Which is where the call stack points when i have the error.

Here is a snippet from my ScreenManager class, this is what ScreenManager.Content is:

_contentManager = game.Content;

Where game is my main game class. My main game class derives from Microsoft.Xna.Framework.Game:

http://pastebin.com/F3VtPdNV

As you can see, there isn't any references to ContentManager in that class. So this is where the trail runs cold for me.

Share this post


Link to post
Share on other sites
Oh, thank you BCullis, that is most certainly the cause of my woes. I guess i need to create a dummy font named "font"? I'm not sure why DebugView does this but oh well, at least i know the cause of my problems.

I'll post my results shortly.

Share this post


Link to post
Share on other sites
Okay, so despite having font.spritefont in my fonts folder with all the others, it still errors and says it cannot find "font".

What directory should i have font.spritefont in? I checked the DebugView folder, and there is indeed a font.spritefont file there, yet it doesn't seem to get loaded by the ContentManager.edit: I added it to my folder and it seems to work. Cheers all, thanks for the help.

Share this post


Link to post
Share on other sites

Okay, so despite having font.spritefont in my fonts folder with all the others, it still errors and says it cannot find "font".

What directory should i have font.spritefont in? I checked the DebugView folder, and there is indeed a font.spritefont file there, yet it doesn't seem to get loaded by the ContentManager.edit: I added it to my folder and it seems to work. Cheers all, thanks for the help.


Put the font.spritefont in your root content directory.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement