When downloading a building asset, BuildingAssetRepository truncates the existing cached .gltf to empty BEFORE the new download has succeeded:
stream = response.body().byteStream();
FileHandle handle = Gdx.files.external("assets/" + name + ".gltf");
handle.writeString("", false); // wipes the existing cached file first
File file = handle.file();
out = Files.newOutputStream(file.toPath());
byte[] buffer = new byte[8192];
int readBytes;
while ((readBytes = stream.read(buffer)) != -1)
out.write(buffer, 0, readBytes);
So the flow is: clear the old file, then stream the new bytes in. If the stream fails partway (network drop mid-download), the previously-working cached model is now gone or partial, and saveLocalBuildingVersion was never reached so the .meta still points at the old version. Depending on how the version compare lands next launch, the client can end up loading a truncated/empty gltf and that building silently fails to load, even though a perfectly good copy existed before the failed update.
Standard fix is to download to a temp file (e.g. <name>.gltf.tmp) and only rename it over the real file once the download completes successfully, so a failed update leaves the old asset intact.
Minor related note: name is concatenated straight into the file path with no sanitization, so a building name containing path characters would write outside the assets dir. Server-controlled today, but worth guarding.
File: core/src/com/focus/kingdom/asset/BuildingAssetRepository.java, download(), around line 105-125.
When downloading a building asset, BuildingAssetRepository truncates the existing cached .gltf to empty BEFORE the new download has succeeded:
So the flow is: clear the old file, then stream the new bytes in. If the stream fails partway (network drop mid-download), the previously-working cached model is now gone or partial, and
saveLocalBuildingVersionwas never reached so the .meta still points at the old version. Depending on how the version compare lands next launch, the client can end up loading a truncated/empty gltf and that building silently fails to load, even though a perfectly good copy existed before the failed update.Standard fix is to download to a temp file (e.g.
<name>.gltf.tmp) and only rename it over the real file once the download completes successfully, so a failed update leaves the old asset intact.Minor related note:
nameis concatenated straight into the file path with no sanitization, so a building name containing path characters would write outside the assets dir. Server-controlled today, but worth guarding.File:
core/src/com/focus/kingdom/asset/BuildingAssetRepository.java, download(), around line 105-125.