C client: Fix crashing when selecting font list

This commit is contained in:
UnknownShadow200 2018-10-01 20:49:01 +10:00
parent 837fd1cf05
commit d39ad38852
6 changed files with 34 additions and 36 deletions

View File

@ -883,12 +883,13 @@ NBT_END,
static ReturnCode Cw_WriteBockDef(struct Stream* stream, Int32 b) {
UInt8 tmp[512];
bool sprite = Block_Draw[b] == DRAW_SPRITE;
union IntAndFloat speed;
Mem_Copy(tmp, cw_meta_def, sizeof(cw_meta_def));
{
tmp[13] = b;
tmp[28] = Block_Collide[b];
union IntAndFloat speed; speed.f = Block_SpeedMultiplier[b];
speed.f = Block_SpeedMultiplier[b];
Stream_SetU32_BE(&tmp[37], speed.u);
tmp[56] = (UInt8)Block_GetTexLoc(b, FACE_YMAX);

View File

@ -52,19 +52,9 @@ bool PackedCol_Unhex(UInt8 hex, Int32* value) {
}
void PackedCol_ToHex(String* str, PackedCol value) {
UInt8 input[3] = { value.R, value.G, value.B };
char hex[7];
Int32 i;
for (i = 0; i < 3; i++) {
Int32 cur = input[i], hi = cur >> 4, lo = cur & 0x0F;
/* 48 = index of 0, 55 = index of (A - 10) */
hex[i * 2 + 0] = hi < 10 ? (hi + 48) : (hi + 55);
hex[i * 2 + 1] = lo < 10 ? (lo + 48) : (lo + 55);
}
hex[6] = '\0';
String_AppendConst(str, hex);
String_AppendHex(str, value.R);
String_AppendHex(str, value.G);
String_AppendHex(str, value.B);
}
bool PackedCol_TryParseHex(const String* str, PackedCol* value) {

View File

@ -29,14 +29,14 @@ PackedCol PackedCol_Create3(UInt8 r, UInt8 g, UInt8 b);
UInt32 PackedCol_ToARGB(PackedCol col);
PackedCol PackedCol_Scale(PackedCol value, float t);
PackedCol PackedCol_Lerp(PackedCol a, PackedCol b, float t);
void PackedCol_ToHex(String* str, PackedCol value);
bool PackedCol_TryParseHex(const String* str, PackedCol* value);
bool PackedCol_Unhex(UInt8 hex, Int32* value);
NOINLINE_ void PackedCol_ToHex(String* str, PackedCol value);
NOINLINE_ bool PackedCol_TryParseHex(const String* str, PackedCol* value);
NOINLINE_ bool PackedCol_Unhex(UInt8 hex, Int32* value);
#define PACKEDCOL_SHADE_X 0.6f
#define PACKEDCOL_SHADE_Z 0.8f
#define PACKEDCOL_SHADE_YMIN 0.5f
/* Retrieves shaded colours for ambient block face lighting. */
/* Retrieves shaded colours for ambient block face lighting */
void PackedCol_GetShaded(PackedCol normal, PackedCol* xSide, PackedCol* zSide, PackedCol* yMin);
#define PACKEDCOL_WHITE PACKEDCOL_CONST(255, 255, 255, 255)

View File

@ -763,7 +763,7 @@ static void Font_DirCallback(const String* srcPath, void* obj) {
if (error) return;
bool styled = (face->style_flags & FT_STYLE_FLAG_BOLD) || (face->style_flags & FT_STYLE_FLAG_ITALIC);
if (!styled && face->family_name) {
if (!styled && face->family_name && (face->face_flags & FT_FACE_FLAG_SCALABLE)) {
StringsBuffer_Add(&fonts_list, &path);
path.length = 0;

View File

@ -226,30 +226,36 @@ bool String_AppendReal32(String* str, float num, Int32 fracDigits) {
return true;
}
NOINLINE_ static bool String_Hex32(String* str, UInt32 value) {
char hex[9]; hex[8] = '\0';
Int32 i;
for (i = 0; i < 8; i++) {
UInt32 nibble = value & 0x0F;
bool String_AppendHex(String* str, UInt8 value) {
/* 48 = index of 0, 55 = index of (A - 10) */
hex[7 - i] = nibble < 10 ? (nibble + 48) : (nibble + 55);
value >>= 4;
UInt8 hi = (value >> 4) & 0xF;
char c_hi = hi < 10 ? (hi + 48) : (hi + 55);
UInt8 lo = value & 0xF;
char c_lo = lo < 10 ? (lo + 48) : (lo + 55);
return String_Append(str, c_hi) && String_Append(str, c_lo);
}
NOINLINE_ static bool String_Hex32(String* str, UInt32 value) {
bool appended;
Int32 shift;
for (shift = 24; shift >= 0; shift -= 8) {
UInt8 part = (UInt8)(value >> shift);
appended = String_AppendHex(str, part);
}
return String_AppendConst(str, hex);
return appended;
}
NOINLINE_ static bool String_Hex64(String* str, UInt64 value) {
char hex[17]; hex[16] = '\0';
Int32 i;
bool appended;
Int32 shift;
for (i = 0; i < 16; i++) {
UInt32 nibble = (UInt32)(value & 0x0F);
/* 48 = index of 0, 55 = index of (A - 10) */
hex[15 - i] = nibble < 10 ? (nibble + 48) : (nibble + 55);
value >>= 4;
for (shift = 56; shift >= 0; shift -= 8) {
UInt8 part = (UInt8)(value >> shift);
appended = String_AppendHex(str, part);
}
return String_AppendConst(str, hex);
return appended;
}
bool String_AppendConst(String* str, const char* src) {

View File

@ -61,6 +61,7 @@ NOINLINE_ bool String_AppendReal32(String* str, float num, Int32 fracDigits); /*
NOINLINE_ bool String_AppendConst(String* str, const char* src);
NOINLINE_ bool String_AppendString(String* str, const String* src);
NOINLINE_ bool String_AppendColorless(String* str, const String* src);
NOINLINE_ bool String_AppendHex(String* str, UInt8 value);
NOINLINE_ Int32 String_IndexOf(const String* str, char c, Int32 offset);
NOINLINE_ Int32 String_LastIndexOf(const String* str, char c);