Fix issues with fallback fonts

Fixed TMP subobjects being deleted, causing fallback fonts to fail in some situations.
closes #24
feature-saving
Andrew Cassidy 4 years ago
parent ac1289a46e
commit ea8c069d68

@ -6,7 +6,7 @@
{ {
"MAJOR":0, "MAJOR":0,
"MINOR":2, "MINOR":2,
"PATCH":2, "PATCH":3,
"BUILD":0 "BUILD":0
}, },
"KSP_VERSION": "KSP_VERSION":

@ -1,4 +1,4 @@
# Conformal Decals v0.2.2 # Conformal Decals v0.2.3
[![Build Status](https://travis-ci.org/drewcassidy/KSP-Conformal-Decals.svg?branch=release)](https://travis-ci.org/drewcassidy/KSP-Conformal-Decals) [![Art: CC BY-SA 4.0](https://img.shields.io/badge/Art%20License-CC%20BY--SA%204.0-orange.svg)](https://creativecommons.org/licenses/by-sa/4.0/) [![Code: GPL v3](https://img.shields.io/badge/Code%20License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Build Status](https://travis-ci.org/drewcassidy/KSP-Conformal-Decals.svg?branch=release)](https://travis-ci.org/drewcassidy/KSP-Conformal-Decals) [![Art: CC BY-SA 4.0](https://img.shields.io/badge/Art%20License-CC%20BY--SA%204.0-orange.svg)](https://creativecommons.org/licenses/by-sa/4.0/) [![Code: GPL v3](https://img.shields.io/badge/Code%20License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
![Screenshot](http://pileof.rocks/KSP/images/ConformalDecalsHeader.png) ![Screenshot](http://pileof.rocks/KSP/images/ConformalDecalsHeader.png)

@ -93,7 +93,7 @@ namespace ConformalDecals {
_shaderBlacklist.Add(shaderName); _shaderBlacklist.Add(shaderName);
} }
} }
var allFonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>(); var allFonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
ParseUtil.ParseStringIndirect(ref _fallbackFontName, node, "fallbackFont"); ParseUtil.ParseStringIndirect(ref _fallbackFontName, node, "fallbackFont");
FallbackFont = allFonts.First(o => o.name == _fallbackFontName); FallbackFont = allFonts.First(o => o.name == _fallbackFontName);
@ -103,14 +103,14 @@ namespace ConformalDecals {
try { try {
var name = ParseUtil.ParseString(fontNode, "name"); var name = ParseUtil.ParseString(fontNode, "name");
if (string.IsNullOrEmpty(name)) throw new FormatException(); if (string.IsNullOrEmpty(name)) throw new FormatException();
var fontAsset = allFonts.First(o => o.name == name); var fontAsset = allFonts.First(o => o.name == name);
if (fontAsset == null) throw new FormatException($"Could not find font asset named {name}"); if (fontAsset == null) throw new FormatException($"Could not find font asset named {name}");
if (!fontAsset.fallbackFontAssets.Contains(FallbackFont)) { if (!fontAsset.fallbackFontAssets.Contains(FallbackFont)) {
fontAsset.fallbackFontAssets.Add(FallbackFont); fontAsset.fallbackFontAssets.Add(FallbackFont);
} }
var font = new DecalFont(name, fontNode, fontAsset); var font = new DecalFont(name, fontNode, fontAsset);
_fontList.Add(font.Name, font); _fontList.Add(font.Name, font);
} }

@ -29,7 +29,6 @@ namespace ConformalDecals.Text {
var loadedFonts = bundle.LoadAllAssets<TMP_FontAsset>(); var loadedFonts = bundle.LoadAllAssets<TMP_FontAsset>();
foreach (var font in loadedFonts) { foreach (var font in loadedFonts) {
Logging.Log($"Adding font {font.name}"); Logging.Log($"Adding font {font.name}");
font.fallbackFontAssets.Add(FallbackFont);
} }
} }

@ -89,9 +89,11 @@ namespace ConformalDecals.Text {
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D12) { if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D12) {
textRenderTextureFormat = RenderTextureFormat.ARGB32; // DirectX is dumb textRenderTextureFormat = RenderTextureFormat.ARGB32; // DirectX is dumb
} }
if (!SystemInfo.SupportsTextureFormat(textTextureFormat)) { if (!SystemInfo.SupportsTextureFormat(textTextureFormat)) {
Logging.LogError($"Text texture format {textTextureFormat} not supported on this platform."); Logging.LogError($"Text texture format {textTextureFormat} not supported on this platform.");
} }
if (!SystemInfo.SupportsRenderTextureFormat(textRenderTextureFormat)) { if (!SystemInfo.SupportsRenderTextureFormat(textRenderTextureFormat)) {
Logging.LogError($"Text texture format {textRenderTextureFormat} not supported on this platform."); Logging.LogError($"Text texture format {textRenderTextureFormat} not supported on this platform.");
} }
@ -279,9 +281,24 @@ namespace ConformalDecals.Text {
// CLEAR SUBMESHES // CLEAR SUBMESHES
for (int i = 0; i < transform.childCount; i++) { for (int i = 0; i < transform.childCount; i++) {
Destroy(transform.GetChild(i).gameObject); var child = transform.GetChild(i);
var renderer = child.GetComponent<MeshRenderer>();
var filter = child.GetComponent<MeshFilter>();
if (filter == null || renderer == null) {
Logging.Log("TMP Sub object has no filter or renderer, destroying");
Destroy(child.gameObject);
}
if (filter.mesh.vertexCount < 3) {
Logging.Log("TMP Sub object has no mesh, destroying");
Destroy(child.gameObject);
}
renderer.enabled = false;
} }
_tmp.ClearMesh(true);
return new TextRenderOutput(texture, window); return new TextRenderOutput(texture, window);
} }
} }

@ -1,3 +1,8 @@
v0.2.3
------
- Fixes:
- Fixed TMP subobjects being deleted, causing fallback fonts to fail in some situations.
v0.2.2 v0.2.2
------ ------
- Fixes: - Fixes:

Loading…
Cancel
Save