Browse Source

Fix issue with corrupted texture cache

If the texture cache doesn't return images in exactly the order or way
that libHSPlasma is expecting, it raises a RuntimeError. We can detect
that we used a cached image and regenerate the data in that case...
instead of just outright failing with "image data size mismatch".
pull/133/head
Adam Johnson 6 years ago
parent
commit
febfb3dd42
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 31
      korman/exporter/material.py

31
korman/exporter/material.py

@ -781,16 +781,27 @@ class MaterialConverter:
cached_image = texcache.get_from_texture(key, compression) cached_image = texcache.get_from_texture(key, compression)
if cached_image is None: if cached_image is None:
if key.is_cube_map: numLevels, width, height, data = self._finalize_cache(texcache, key, image, name, compression, dxt)
numLevels, width, height, data = self._finalize_cube_map(key, image, name, compression, dxt) self._finalize_bitmap(key, owners, name, numLevels, width, height, compression, dxt, data)
else:
numLevels, width, height, data = self._finalize_single_image(key, image, name, compression, dxt)
texcache.add_texture(key, numLevels, (width, height), compression, data)
else: else:
width, height = cached_image.export_size width, height = cached_image.export_size
data = cached_image.image_data data = cached_image.image_data
numLevels = cached_image.mip_levels numLevels = cached_image.mip_levels
# If the cached image data is junk, PyHSPlasma will raise a RuntimeError,
# so we'll attempt a recache...
try:
self._finalize_bitmap(key, owners, name, numLevels, width, height, compression, dxt, data)
except RuntimeError:
self._report.warn("Cached image is corrupted! Recaching image...", indent=1)
numLevels, width, height, data = self._finalize_cache(texcache, key, image, name, compression, dxt)
self._finalize_bitmap(key, owners, name, numLevels, width, height, compression, dxt, data)
inc_progress()
def _finalize_bitmap(self, key, owners, name, numLevels, width, height, compression, dxt, data):
mgr = self._mgr
# Now we poke our new bitmap into the pending layers. Note that we have to do some funny # Now we poke our new bitmap into the pending layers. Note that we have to do some funny
# business to account for per-page textures # business to account for per-page textures
pages = {} pages = {}
@ -833,9 +844,15 @@ class MaterialConverter:
elif isinstance(owner, plImageLibMod): elif isinstance(owner, plImageLibMod):
owner.addImage(texture.key) owner.addImage(texture.key)
else: else:
raise RuntimeError(owner.ClassName()) raise NotImplementedError(owner.ClassName())
inc_progress() def _finalize_cache(self, texcache, key, image, name, compression, dxt):
if key.is_cube_map:
numLevels, width, height, data = self._finalize_cube_map(key, image, name, compression, dxt)
else:
numLevels, width, height, data = self._finalize_single_image(key, image, name, compression, dxt)
texcache.add_texture(key, numLevels, (width, height), compression, data)
return numLevels, width, height, data
def _finalize_cube_map(self, key, image, name, compression, dxt): def _finalize_cube_map(self, key, image, name, compression, dxt):
oWidth, oHeight = image.size oWidth, oHeight = image.size

Loading…
Cancel
Save