Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Glyph.Advance = 1093664768? (+ SEHExceptions)  (Read 2644 times)

0 Members and 1 Guest are viewing this topic.

AtomCrafty

  • Newbie
  • *
  • Posts: 8
    • View Profile
Glyph.Advance = 1093664768? (+ SEHExceptions)
« on: July 27, 2017, 08:59:19 pm »
Hey there,

a few days ago I started suddenly getting SEHExceptions or AccessViolationExceptions from within the unmanaged SFML assemblies every time I tried to call Font.GetGlyph.
Right before the crash, SFML writes the following error message to the console:

Failed to add a new character to the font: the maximum texture size has been reached.

Keep in mind that this happens on the very first glyph with a font size of 16 and a copy of C:\Windows\Fonts\arial.ttf, so under normal circumstances the buffer texture should be tiny (VRAM certainly isn't an issue).

So I decided to create a clean project with a freshly downloaded copy of SFML. This time it didn't crash, but I noticed something odd: The 'Advance' property of any glyph obtained by Font.GetGlyph is waaay off, somewhere in the single digit billions... I heavily doubt that's the expected behavior.
The generated texture looks normal though.

The issue occurs even if execute the program on another machine.

This is the code I used for the test:

using System;
using SFML.Graphics;

namespace SFMLtests {
        class Program {
                static void Main(string[] args) {
                        var font = new Font("arial.ttf");

                        var a = font.GetGlyph('A', 16, false);
                        var b = font.GetGlyph('B', 16, false);
                        var c = font.GetGlyph('C', 16, false);

                        Console.WriteLine(a.Advance);
                        Console.WriteLine(b.Advance);
                        Console.WriteLine(c.Advance);
                        Console.WriteLine();
                        Console.WriteLine(a.Bounds);
                        Console.WriteLine(b.Bounds);
                        Console.WriteLine(c.Bounds);
                        Console.WriteLine();
                        Console.WriteLine(a.TextureRect);
                        Console.WriteLine(b.TextureRect);
                        Console.WriteLine(c.TextureRect);

                        font.GetTexture(16).CopyToImage().SaveToFile("font.png");

                        Console.ReadLine();
                }
        }
}

And this is the output I'm getting:

1093664768
1092616192
1093664768

[FloatRect] Left(-1) Top(-12) Width(12) Height(12)
[FloatRect] Left(0) Top(-12) Width(10) Height(12)
[FloatRect] Left(0) Top(-12) Width(11) Height(12)

[IntRect] Left(1) Top(4) Width(12) Height(12)
[IntRect] Left(15) Top(4) Width(10) Height(12)
[IntRect] Left(27) Top(4) Width(11) Height(12)

Specs (In case that will be relevant)
Windows 10 Professional 64 bit (version 1703)
Intel Core i7-3820 (3.6 GHz)
32 GB memory
NVIDIA GeForce GTX 970 2-way SLI


Cheers, Mario
« Last Edit: July 27, 2017, 09:04:39 pm by AtomCrafty »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Glyph.Advance = 1093664768? (+ SEHExceptions)
« Reply #1 on: July 27, 2017, 09:27:05 pm »
Could this be a version mismatch between SFML.Net and CSFML? Which version(s) are you using?
Laurent Gomila - SFML developer

AtomCrafty

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Glyph.Advance = 1093664768? (+ SEHExceptions)
« Reply #2 on: July 28, 2017, 12:07:58 am »
The test was run with a fresh copy of SFML.Net 2.2 and the included "extlib" CSFML libraries from here (All compilers - 32-bit): https://www.sfml-dev.org/download/sfml.net/

For my main program this could indeed be an issue, since I'm using a non-standard SFML setup there.
I've compiled SFML.Net myself for AnyCpu and embedded both the 32bit and 64bit CSFML binaries inside of my assembly using Costura.Fody (https://github.com/Fody/Costura) to avoid having to ship multiple files.
I believe I'm using the CSFML 2.4 binaries with SFML.Net 2.2 there, let me check if I get different results with CSFML 2.2 (everything else works fine as far as I'm concerned).

Cheers, Mario

AtomCrafty

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Glyph.Advance = 1093664768? (+ SEHExceptions)
« Reply #3 on: July 28, 2017, 12:35:25 am »
Okay, quick update:
With CSFML 2.2 it doesn't crash (my fault for mixing versions), however the incorrect glyph measurements persist.
Again, the buffer texture looks fine.



"Hello, world!"


Cheers, Mario

AtomCrafty

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Glyph.Advance = 1093664768? (+ SEHExceptions)
« Reply #4 on: July 28, 2017, 12:44:19 am »
I think I've identified the issue:

Decimal 1101529088 corresponds to binary 0-10000011-01010000000000000000000, which looks a lot like a 32 bit floating point value...
21.0f to be exact, which would be about the value I'd expect for a font size of 30.

SFML.Net 2.2 declares Advance as int, while SFML 2.2 (and therefore CSFML 2.2) handle it as a float value.
The current state of the git repository already declares it as float, but that won't be of any help until SFML.Net 2.4 is released (https://github.com/SFML/SFML.Net/blob/master/src/Graphics/Glyph.cs).

I guess I'll just change the declaration in my own copy if SFML.Net :)

Btw, I've been wondering about this: Is there any particular reason SFML.Net comes in separate 32 bit and 64 bit assemblies? AnyCpu works fine for me as long as I load the correct CSFML binary on runtime.

Cheers, Mario
« Last Edit: July 28, 2017, 01:24:10 am by AtomCrafty »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Glyph.Advance = 1093664768? (+ SEHExceptions)
« Reply #5 on: July 28, 2017, 08:02:29 am »
You should be able to use the latest master (just needs more testing before release), or if you want to be safe, version 2.3; I'm surprised it is not released, it's properly tagged in the repository.
Laurent Gomila - SFML developer

AtomCrafty

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Glyph.Advance = 1093664768? (+ SEHExceptions)
« Reply #6 on: July 28, 2017, 06:12:03 pm »
Thanks, I'm now using CSFML 2.4 with the latest SFML.Net master, seems to work fine :)

 

anything