An error occured in the fragment kernel

Hi,

I have an app that uses some .otf fonts. They work fine in Windows 10, iOS and Android, but on Windows 7 they fail to load (console reports this). I am able to view and install those fonts into Windows 7 with no problems, but they just won’t load in corona. (build 2830)

To try and work around the problem i converted all the otf fonts to ttf fonts using the “freefontconverter” website. I no longer get the errors in the corona console but the fonts just load as blank (ie all text using that font is invisible). I am now also getting the “An error occured in the fragment kernel” error shown in the attached image since converting those fonts.

I am loading the fonts using display.newText with the font=“fontname.ttf” param.

Any suggestions?

Cheers

That error message has nothing to do with fonts.

That error means the video driver failed to compile and load an OpenGL shader (aka: graphics effect) due to a syntax error in the shader program.

Is your app using a custom shader effect?

Ah ok yep i am using some custom shader effects, its probably just due to the Win 7 Virtual Machine I was running it in to try and work out why the fonts aren’t working in Win 7.

Could you shed some light on the whole font thing? I have 6 OTF fonts, none of which will load on Windows 7 with Corona. I can view and install them fine into windows 7, they appear in the windows Character Map fine as well once installed, but they just wont load from Corona (simulator or win32 built app) using display.newText with font=“fontname.otf”.

I did also try converting them to ttf fonts as well (i have a heap of other ttf fonts that work fine), but they still dont work even after being converted. Any suggestions as to how to get them to work?

First, make sure to load your fonts by file name, including the extension.  This way they don’t have to be installed into the system.

Next, check your log after your project attempts to load a font.  If you see a message like the below, then we know the Windows OS has failed to load the font file.

   “WARNING: Could not load font <YourFontName>. Using default font.”

If you are not seeing the above warning message, then make sure that each of your font files have different Font Family Names.  This is important because many of Microsoft’s native Win32 APIs can only differentiate between fonts by their family names once loaded into the app.  So, the first Font Family Name that gets loaded wins.  If you attempt to load another font file having the same font family name, the system will assume it was *already* loaded and use the first font loaded by that family name.  I’m pretty sure Android works the same way.

You can identify the font family names of each font by simply double clicking on the font file.

I am always using the full font name with extension. 

The console does indeed say “WARNING: Could not load font <YourFontName>. Using default font.”. What im try to understand though is why it wont load them when windows itself has no problems with it? (ie can view and install fine in windows)

We use Microsoft’s native C/C++ Win32 APIs to load font files.  So, if Microsoft’s APIs can’t load your font files, then there is some aspect about your files that they have a problem with, such as errors in the file (fault tolerance issue) or an issue with its internal format.  You’ll either have to keep tinker with the font until it works or choose a different font file.

Ok thanks, so to clarify are you just using either AddFontResource or AddFontResourceEx?

I figure it might be helpful for me to write a win32 application using the same functions to see what errors its reporting to help figure out why the font isn’t loading.

We load a font file using *both* of the following Microsoft functions.

  • Gdiplus::PrivateFontCollection::AddFontFile()
  • AddFontResourceEx()

Both of the above function have to load a font file successfully or else we’ll log a warning and fallback to using a system default font.  The reason is because some of our features such as native.newTextField() use Microsoft’s older GDI APIs and other Corona features such as display.newText() use Microsoft’s GDI+ APIs.

Unfortunately, the AddFontResourceEx() function doesn’t provide any detailed error information.  It simply returns zero upon failure.  That function doesn’t provide any details via GetLastError() eith.

The Gdiplus::PrivateFontCollection::AddFontFile() method does provide an error result code, but nothing useful in this case.

   https://msdn.microsoft.com/en-us/library/windows/desktop/ms534175(v=vs.85).aspx

If you want, you can give daily build #2693 a go and see if it’s able to load your font files.

   http://developer.coronalabs.com/release/2015/2693

We were not loading fonts via the AddFontResourceEx() function in that build and older versions.  We were only using Microsoft’s GDI+ API to load fonts back then.

Hi Joshua,

Thanks for the feedback. 

I had been able setup a test c++  application using Gdiplus::PrivateFontCollection::AddFontFile() and was able to reproduce the failure to load on Win7. As you mentioned, the error was “File not found” which was useless (and untrue) but there are plenty of links saying that error gets returned when windows doesnt like something about the font. 

I have managed to convert the problematic fonts (i had issues with all OTF and some TTF fonts) in Windows 7 so that they now work fine.

In all cases i successfuly used the open source FontForge application to do the conversion. 

For the OTF files that didnt work i had to change the Layers to “Quadratic” instead of “Cubic” (Element->Font Info->Layers) and then save as TTF (File->Generate Fonts) with it set as “TrueType” to make it work. (default options were fine)

For the TTF files that were not loading properly (which for me was any TTF which is not the standard regular font version, eg it was the Bold or Italic version) i just had to load it in font forge and resave it (generate fonts) to make it compatible.

Hopefully that helps someone trying to work around this issue.

*note: i have not yet verified that the converted version of the fonts still work on iOS/Android, i will post a follow up here if they dont.

Cheers

That error message has nothing to do with fonts.

That error means the video driver failed to compile and load an OpenGL shader (aka: graphics effect) due to a syntax error in the shader program.

Is your app using a custom shader effect?

Ah ok yep i am using some custom shader effects, its probably just due to the Win 7 Virtual Machine I was running it in to try and work out why the fonts aren’t working in Win 7.

Could you shed some light on the whole font thing? I have 6 OTF fonts, none of which will load on Windows 7 with Corona. I can view and install them fine into windows 7, they appear in the windows Character Map fine as well once installed, but they just wont load from Corona (simulator or win32 built app) using display.newText with font=“fontname.otf”.

I did also try converting them to ttf fonts as well (i have a heap of other ttf fonts that work fine), but they still dont work even after being converted. Any suggestions as to how to get them to work?

First, make sure to load your fonts by file name, including the extension.  This way they don’t have to be installed into the system.

Next, check your log after your project attempts to load a font.  If you see a message like the below, then we know the Windows OS has failed to load the font file.

   “WARNING: Could not load font <YourFontName>. Using default font.”

If you are not seeing the above warning message, then make sure that each of your font files have different Font Family Names.  This is important because many of Microsoft’s native Win32 APIs can only differentiate between fonts by their family names once loaded into the app.  So, the first Font Family Name that gets loaded wins.  If you attempt to load another font file having the same font family name, the system will assume it was *already* loaded and use the first font loaded by that family name.  I’m pretty sure Android works the same way.

You can identify the font family names of each font by simply double clicking on the font file.

I am always using the full font name with extension. 

The console does indeed say “WARNING: Could not load font <YourFontName>. Using default font.”. What im try to understand though is why it wont load them when windows itself has no problems with it? (ie can view and install fine in windows)

We use Microsoft’s native C/C++ Win32 APIs to load font files.  So, if Microsoft’s APIs can’t load your font files, then there is some aspect about your files that they have a problem with, such as errors in the file (fault tolerance issue) or an issue with its internal format.  You’ll either have to keep tinker with the font until it works or choose a different font file.

Ok thanks, so to clarify are you just using either AddFontResource or AddFontResourceEx?

I figure it might be helpful for me to write a win32 application using the same functions to see what errors its reporting to help figure out why the font isn’t loading.

We load a font file using *both* of the following Microsoft functions.

  • Gdiplus::PrivateFontCollection::AddFontFile()
  • AddFontResourceEx()

Both of the above function have to load a font file successfully or else we’ll log a warning and fallback to using a system default font.  The reason is because some of our features such as native.newTextField() use Microsoft’s older GDI APIs and other Corona features such as display.newText() use Microsoft’s GDI+ APIs.

Unfortunately, the AddFontResourceEx() function doesn’t provide any detailed error information.  It simply returns zero upon failure.  That function doesn’t provide any details via GetLastError() eith.

The Gdiplus::PrivateFontCollection::AddFontFile() method does provide an error result code, but nothing useful in this case.

   https://msdn.microsoft.com/en-us/library/windows/desktop/ms534175(v=vs.85).aspx

If you want, you can give daily build #2693 a go and see if it’s able to load your font files.

   http://developer.coronalabs.com/release/2015/2693

We were not loading fonts via the AddFontResourceEx() function in that build and older versions.  We were only using Microsoft’s GDI+ API to load fonts back then.

Hi Joshua,

Thanks for the feedback. 

I had been able setup a test c++  application using Gdiplus::PrivateFontCollection::AddFontFile() and was able to reproduce the failure to load on Win7. As you mentioned, the error was “File not found” which was useless (and untrue) but there are plenty of links saying that error gets returned when windows doesnt like something about the font. 

I have managed to convert the problematic fonts (i had issues with all OTF and some TTF fonts) in Windows 7 so that they now work fine.

In all cases i successfuly used the open source FontForge application to do the conversion. 

For the OTF files that didnt work i had to change the Layers to “Quadratic” instead of “Cubic” (Element->Font Info->Layers) and then save as TTF (File->Generate Fonts) with it set as “TrueType” to make it work. (default options were fine)

For the TTF files that were not loading properly (which for me was any TTF which is not the standard regular font version, eg it was the Bold or Italic version) i just had to load it in font forge and resave it (generate fonts) to make it compatible.

Hopefully that helps someone trying to work around this issue.

*note: i have not yet verified that the converted version of the fonts still work on iOS/Android, i will post a follow up here if they dont.

Cheers