mwl4 / ConverterPIX

Conversion tool that is able to convert from the game binary formats (.pmx) to the middle formats (.pix) in Euro Truck Simulator 2 & American Truck Simulator.
https://truckersmp.com/
GNU Lesser General Public License v3.0
67 stars 27 forks source link

Better protection against broken ppd files #37

Closed theHarven closed 4 years ago

theHarven commented 4 years ago

In ATS 1.38 there is a prefab which causes the converter to crash: /prefab/corners/sidewalk_fork_2-2_country_2-1_country_r.ppd

It crashes at src/prefab/prefab.cpp:706

TerrainPointVariant data = m_terrainPointVariants[node->m_variantIdx + j];

because for some reason this prefab has node->m_variantCount set to 2 (for both nodes) but there are no ppd_terrain_point_variant_t blocks in the file - header->m_terrain_point_variant_count == 0 and header->m_terrain_point_variant_offset == header->m_map_point_offset.

I made a simple check to see if node->m_variantIdx + node->m_variantCount > m_terrainPointVariants.size() and if it is I'm printing a warning message and setting variant count to 0 so that the file can still be converted but without terrain point variants.

After converting the file with this version it loads in blender but there are some error messages (unrelated to terrain point variants I think):

ERROR SUMMARY:
================
> Map connection out of range: (0, 769)
> Map connection out of range: (1, 770)
> Map connection out of range: (1, -1064304636)
> Map connection out of range: (1, -1041235969)
================

it seems there are wrong values for Neighbours in pip file:

MapPoint {
     Index: 0
     MapVisualFlags: 0
     MapNavFlags: 7
     Position: ( &00000007  &00000007  &00000e00 )
     Neighbours: ( 769 0 0 0 1 0 )
}
MapPoint {
     Index: 1
     MapVisualFlags: 0
     MapNavFlags: 0
     Position: ( &00000000  &00000001  &00000e00 )
     Neighbours: ( 770 -1064304636 0 -1041235969 0 0 )
}

but that's what is in the ppd file - this only reassured me that this ppd file is broken.