Skip to content

Commit

Permalink
Fixed 'Couldn't find glyph' exception bug
Browse files Browse the repository at this point in the history
  • Loading branch information
iZucked committed Aug 14, 2022
1 parent c5770a4 commit 6d318e5
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/symbol.py
@@ -1,6 +1,8 @@
from random import choice, randrange
from typing import List

import pygame
from pygame.font import Font

from config import Config

Expand All @@ -15,6 +17,18 @@
font = pygame.font.Font(Config.FONT_PATH, Config.FONT_SIZE)


def get_char_surfaces(font: Font, char_set: List[chr], char_color: pygame.Color) -> List[pygame.Surface]:
surfaces = []
for char in char_set:
try:
surfaces.append(font.render(char, True, char_color))
except pygame.error as e:
# In case of 'Couldn't find glyph' error
if "Couldn't find glyph" in e.args[0]:
continue
return surfaces


class Symbol:

def __init__(self, x, y, speed, color):
Expand All @@ -25,7 +39,7 @@ def __init__(self, x, y, speed, color):
self.interval = randrange(5, 30)
self.state = NOT_PLACED

self.charSet = [font.render(char, True, color) for char in katakana]
self.charSet = get_char_surfaces(font, katakana, color)
self.surface = choice(self.charSet)

def update(self):
Expand Down Expand Up @@ -68,11 +82,11 @@ def __init__(self, pos_x, start_y, placeable_positions_list):
self.next_placement_pos = 0

for n, i in enumerate(
range(
start_y,
start_y - Config.FONT_SIZE * self.column_height,
-Config.FONT_SIZE
)
range(
start_y,
start_y - Config.FONT_SIZE * self.column_height,
-Config.FONT_SIZE
)
):
if n == 0:
# Let first symbol be white
Expand Down Expand Up @@ -110,8 +124,8 @@ def get_white_symbol(self):

def check_white_symbol(self):
if (
self.get_white_symbol().get_y_position() == self.next_placement_pos
and self.next_placement_pos != -1
self.get_white_symbol().get_y_position() == self.next_placement_pos
and self.next_placement_pos != -1
):
self.next_placement_pos = (
self.placeable_positions.pop(0)
Expand Down

0 comments on commit 6d318e5

Please sign in to comment.