Skip to content

Commit

Permalink
Merge pull request supertuxkart#141 from supertuxkart/invisible_quad
Browse files Browse the repository at this point in the history
Fix exception when invisible quad exists in the middle of quad list
  • Loading branch information
vampy authored Mar 7, 2020
2 parents dc33fd8 + 2661752 commit 5adfb78
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions include/StkImage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,18 @@ public static function createImageFromQuadsXML($quad_file, $addon_id)

if (isset($val['attributes']))
{
$visible = True;
if (isset($val['attributes']['INVISIBLE']) && $val['attributes']['INVISIBLE'] === 'yes')
{
continue;
$visible = False;
}
if (isset($val['attributes']['DIRECTION']))
if (!isset($val['attributes']['P0']) || !isset($val['attributes']['P1']) ||
!isset($val['attributes']['P2']) || !isset($val['attributes']['P3']))
{
unset($val['attributes']['DIRECTION']);
throw new FileSystemException('Invalid quad.');
}
$quads[] = array_values($val['attributes']);
$quads[] = array($val['attributes']['P0'], $val['attributes']['P1'],
$val['attributes']['P2'], $val['attributes']['P3'], $visible);
}
}
$quads_count = count($quads);
Expand All @@ -523,6 +526,9 @@ public static function createImageFromQuadsXML($quad_file, $addon_id)
$z_max = null;
for ($i = 0; $i < $quads_count; $i++)
{
// Skip invisible quad
if (!$quads[$i][4])
continue;
for ($j = 0; $j <= 3; $j++)
{
$quads[$i][$j] = explode(' ', $quads[$i][$j]);
Expand Down Expand Up @@ -569,6 +575,9 @@ public static function createImageFromQuadsXML($quad_file, $addon_id)
$z_range = $z_max - $z_min + 1;
for ($i = 0; $i < $quads_count; $i++)
{
// Skip invisible quad
if (!$quads[$i][4])
continue;
for ($j = 0; $j <= 3; $j++)
{
$y = $quads[$i][$j][1] - $y_min;
Expand Down Expand Up @@ -597,6 +606,9 @@ public static function createImageFromQuadsXML($quad_file, $addon_id)
// Paint quads
for ($i = 0; $i < $quads_count; $i++)
{
// Skip invisible quad
if (!$quads[$i][4])
continue;
$color_index = (int)(($quads[$i][0][1] + $quads[$i][1][1] + $quads[$i][2][1] + $quads[$i][3][1]) / 4);
imagefilledpolygon(
$image, // image
Expand Down

0 comments on commit 5adfb78

Please sign in to comment.