fix json parsing errors
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
80382cc83d
commit
d99ef4d2c2
|
@ -226,11 +226,14 @@ static uint8_t json_object_has_key(const json_object_t *object, const char* name
|
||||||
|
|
||||||
while (SDL_strcmp(currentName, name) != 0)
|
while (SDL_strcmp(currentName, name) != 0)
|
||||||
{
|
{
|
||||||
if (currentElement->next != NULL)
|
if (currentElement->next == NULL)
|
||||||
{
|
{
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Key %s not found in JSON!", name);
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Key %s not found in JSON!", name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentElement = currentElement->next;
|
||||||
|
currentName = currentElement->name->string;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -243,9 +246,9 @@ static json_object_element_t* json_object_get_element_by_name(const json_object_
|
||||||
|
|
||||||
while (SDL_strcmp(currentName, name) != 0)
|
while (SDL_strcmp(currentName, name) != 0)
|
||||||
{
|
{
|
||||||
if (currentElement->next != NULL)
|
if (currentElement->next == NULL)
|
||||||
{
|
{
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Key %s not found in JSON!", name);
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Key %s not found in JSON!", name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +272,7 @@ static json_object_t* json_object_get_object(const json_object_t *object, const
|
||||||
|
|
||||||
if (obj == NULL)
|
if (obj == NULL)
|
||||||
{
|
{
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Value with key %s was not an object!", name);
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Value with key %s was not an object!", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -288,7 +291,7 @@ static const char* json_object_get_string(const json_object_t *object, const cha
|
||||||
|
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
{
|
{
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Value with key %s was not a string!", name);
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Value with key %s was not a string!", name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,7 +311,7 @@ static uint32_t json_object_get_uint(const json_object_t *object, const char* na
|
||||||
|
|
||||||
if (num == NULL)
|
if (num == NULL)
|
||||||
{
|
{
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Value with key %s was not a number!", name);
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Value with key %s was not a number!", name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +331,7 @@ static double json_object_get_double(const json_object_t *object, const char* na
|
||||||
|
|
||||||
if (num == NULL)
|
if (num == NULL)
|
||||||
{
|
{
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Value with key %s was not a string!", name);
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Value with key %s was not a string!", name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +364,7 @@ Wellspring_Font* Wellspring_CreateFont(
|
||||||
|
|
||||||
if (jsonObject == NULL)
|
if (jsonObject == NULL)
|
||||||
{
|
{
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Atlas JSON is invalid! Bailing!");
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Atlas JSON is invalid! Bailing!");
|
||||||
Wellspring_free(font->fontBytes);
|
Wellspring_free(font->fontBytes);
|
||||||
Wellspring_free(font);
|
Wellspring_free(font);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -369,7 +372,7 @@ Wellspring_Font* Wellspring_CreateFont(
|
||||||
|
|
||||||
if (SDL_strcmp(jsonObject->start->name->string, "atlas") != 0)
|
if (SDL_strcmp(jsonObject->start->name->string, "atlas") != 0)
|
||||||
{
|
{
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Atlas JSON is invalid! Bailing!");
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Atlas JSON is invalid! Bailing!");
|
||||||
Wellspring_free(jsonRoot);
|
Wellspring_free(jsonRoot);
|
||||||
Wellspring_free(font->fontBytes);
|
Wellspring_free(font->fontBytes);
|
||||||
Wellspring_free(font);
|
Wellspring_free(font);
|
||||||
|
@ -384,7 +387,7 @@ Wellspring_Font* Wellspring_CreateFont(
|
||||||
|
|
||||||
if (SDL_strcmp(atlasType, "msdf") != 0)
|
if (SDL_strcmp(atlasType, "msdf") != 0)
|
||||||
{
|
{
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Atlas is not MSDF! Bailing!");
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Atlas is not MSDF! Bailing!");
|
||||||
Wellspring_free(jsonRoot);
|
Wellspring_free(jsonRoot);
|
||||||
Wellspring_free(font->fontBytes);
|
Wellspring_free(font->fontBytes);
|
||||||
Wellspring_free(font);
|
Wellspring_free(font);
|
||||||
|
@ -422,7 +425,7 @@ Wellspring_Font* Wellspring_CreateFont(
|
||||||
// first codepoint on first range
|
// first codepoint on first range
|
||||||
font->packer.ranges[charRangeIndex].firstCodepoint = codepoint;
|
font->packer.ranges[charRangeIndex].firstCodepoint = codepoint;
|
||||||
}
|
}
|
||||||
else if (codepoint != font->packer.ranges[charRangeIndex].firstCodepoint + font->packer.ranges[charRangeIndex].charCount + 1)
|
else if (codepoint != font->packer.ranges[charRangeIndex].firstCodepoint + font->packer.ranges[charRangeIndex].charCount)
|
||||||
{
|
{
|
||||||
// codepoint is not continuous, start a new range
|
// codepoint is not continuous, start a new range
|
||||||
charRangeIndex += 1;
|
charRangeIndex += 1;
|
||||||
|
@ -436,6 +439,15 @@ Wellspring_Font* Wellspring_CreateFont(
|
||||||
font->packer.ranges[charRangeIndex].data = Wellspring_realloc(font->packer.ranges[charRangeIndex].data, sizeof(PackedChar) * font->packer.ranges[charRangeIndex].charCount);
|
font->packer.ranges[charRangeIndex].data = Wellspring_realloc(font->packer.ranges[charRangeIndex].data, sizeof(PackedChar) * font->packer.ranges[charRangeIndex].charCount);
|
||||||
|
|
||||||
PackedChar *packedChar = &font->packer.ranges[charRangeIndex].data[font->packer.ranges[charRangeIndex].charCount - 1];
|
PackedChar *packedChar = &font->packer.ranges[charRangeIndex].data[font->packer.ranges[charRangeIndex].charCount - 1];
|
||||||
|
packedChar->atlasLeft = 0;
|
||||||
|
packedChar->atlasRight = 0;
|
||||||
|
packedChar->atlasTop = 0;
|
||||||
|
packedChar->atlasBottom = 0;
|
||||||
|
packedChar->planeLeft = 0;
|
||||||
|
packedChar->planeRight = 0;
|
||||||
|
packedChar->planeTop = 0;
|
||||||
|
packedChar->planeBottom = 0;
|
||||||
|
|
||||||
packedChar->xAdvance = json_object_get_double(currentGlyphObject, "advance");
|
packedChar->xAdvance = json_object_get_double(currentGlyphObject, "advance");
|
||||||
|
|
||||||
if (json_object_has_key(currentGlyphObject, "atlasBounds"))
|
if (json_object_has_key(currentGlyphObject, "atlasBounds"))
|
||||||
|
|
Loading…
Reference in New Issue