XNA - Problems With ContentManager

Started by
11 comments, last by Arne Christian Blystad 11 years, 10 months ago
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.
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?

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

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.

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.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)


[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.
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?

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.
Are you loading or drawing using SpriteFonts in your test environment? If so, can we see the code that loads those fonts?
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.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

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.

This topic is closed to new replies.

Advertisement