Diagonal line appears randomly

Hello guys

I had a problem with my project, today when I work on it I start to have weird diagonal line appears randomly

here some screen shot: (some time difficult to see, I add red arrow)


How I draw a rectangle:

    public Texture2D GetNewUnManagedTexture(int width, int height, bool persistente = false) {
        Texture2D t = new Texture2D(GraphicsDevice, width, height);
        if(!persistente) this.TexturesToDispose.Add(t);
        return t;
    }
            private static Dictionary<Color, Texture2D> Pixels = new Dictionary<Color, Texture2D>();
            public static Texture2D GetPixel(Color c) {
                if (Pixels.ContainsKey(c)) return Pixels[c];
                //
                Texture2D texture = GetNewUnManagedTexture(1, 1, true);
                texture.SetData(new[] { c });
                Pixels.Add(c, texture);
                return Pixels[c];
            }

            public static void DrawRectangleS(int x, int y, int w, int h, Color c) =>
                GameData.DrawOnScreen(GetPixel(c), new Rectangle(x, y, w, h), new Rectangle(0, 0, 1, 1), Color.White);

As you can see I have a Dictionary<Color, Texture2D> for store my texture of 1x1 pixels
I do this to avoid to do texture.SetData(new { color }) every frame

Here my method to draw a texture on screen:

    public bool DrawOnScreen(Texture2D texture, Rectangle rPast, Rectangle rCopy, Color color, float angle = 0f) {
        // check
        if (texture == null) return false;
        // reverse and draw or draw directly
        if (rPast.Width < 0) {
            rPast.Width = -rPast.Width;
            this.SpriteBatch.Draw(texture, rPast, rCopy, color, angle, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0f);
        } else if (rPast.Height < 0) {
            rPast.Height = -rPast.Height;
            this.SpriteBatch.Draw(texture, rPast, rCopy, color, angle, new Vector2(0, 0), SpriteEffects.FlipVertically, 0f);
        } else if (Math.Abs(angle) > .001f)
            this.SpriteBatch.Draw(texture, rPast, rCopy, color, angle, new Vector2(rCopy.Width / 2f, rCopy.Height / 2f), SpriteEffects.None, 0f);
        else
            this.SpriteBatch.Draw(texture, rPast, rCopy, color);
        return true;
    }

Can’t fine what makes them appear and how to fix it, some one with an idea I can work on ? :disappointed_relieved:

IDE : VS2015
Mono : 3.5
Template : Desktop OnpenGL

Ok, found it!

When I preload the spritefont the line disappear but… why ? :open_mouth:

how I load font :

    // =================================================================================
    //  o GetSpriteFontFor
    private Dictionary<string, SpriteFont> Fonts =  new Dictionary<string, SpriteFont>();
    private SpriteFont GetSpriteFontFor(FontSize size) {
        string name = "Font/font_"+((int)size).ToString("D2")+"_" + DsrRatio;
        if (!this.Fonts.ContainsKey(name))
            this.Fonts.Add(name, this.Content.Load<SpriteFont>(name));
        return this.Fonts[name];
    }

FontSize it’s a enum like this { small, medium, large, menu …etc}

if i start the game without doing anything else and let the game load font when need it I have the black diagonal line
but if I add this line in Game.Initialize all works well :cold_sweat:

        foreach (FontSize fontSize in Enum.GetValues(typeof(FontSize)))
            GetSpriteFontFor(fontSize);