diff --git a/bemani/format/afp/render.py b/bemani/format/afp/render.py index 66af1c0..3c5f67f 100644 --- a/bemani/format/afp/render.py +++ b/bemani/format/afp/render.py @@ -297,7 +297,11 @@ class AFPRenderer(VerboseOutput): transform = parent_transform.multiply(renderable.tag.transform or Matrix.identity()) # Calculate the inverse so we can map canvas space back to texture space. - inverse = transform.inverse() + try: + inverse = transform.inverse() + except ZeroDivisionError: + print(f"WARNING: Transform Matrix {transform} has zero scaling factor, making it non-invertible!") + return # Render individual shapes if this is a sprite. if renderable.tag.source_tag_id in self.__registered_sprites: diff --git a/bemani/format/afp/types/generic.py b/bemani/format/afp/types/generic.py index 01c3d9a..5eafff3 100644 --- a/bemani/format/afp/types/generic.py +++ b/bemani/format/afp/types/generic.py @@ -123,14 +123,19 @@ class Matrix: def inverse(self) -> "Matrix": denom = (self.a * self.d - self.b * self.c) - return Matrix( - a=self.d / denom, - b=-self.b / denom, - c=-self.c / denom, - d=self.a / denom, - tx=(self.c * self.ty - self.d * self.tx) / denom, - ty=-(self.a * self.ty - self.b * self.tx) / denom, - ) + try: + return Matrix( + a=self.d / denom, + b=-self.b / denom, + c=-self.c / denom, + d=self.a / denom, + tx=(self.c * self.ty - self.d * self.tx) / denom, + ty=-(self.a * self.ty - self.b * self.tx) / denom, + ) + except ZeroDivisionError: + pass + + raise ZeroDivisionError(f"Matrix({self}) cannot be inverted!") def __repr__(self) -> str: return f"a: {round(self.a, 5)}, b: {round(self.b, 5)}, c: {round(self.c, 5)}, d: {round(self.d, 5)}, tx: {round(self.tx, 5)}, ty: {round(self.ty, 5)}"