Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiledmap crashes when object layer with single images is used #526

Open
Dennis1000 opened this issue Jul 15, 2023 · 0 comments
Open

Tiledmap crashes when object layer with single images is used #526

Dennis1000 opened this issue Jul 15, 2023 · 0 comments

Comments

@Dennis1000
Copy link
Contributor

The Tiled-editor allows object layers with separate independend images instead of an single tileset image (see attached tmx file).

The TCastleTiledMapData.TImage.DetermineSize function then crashes, because the URL is empty.
It's called in CastleTiledMapData.TTileset.Load function, because this tileset doesn't have any width/height settings
and the code tries to get them via the image - which isn't there as well.
That does mean a tileset won't need an image object at all times.

There is an easy fix (if the image object is created in the tileset constructor as of now) but not filled in an object layer:

TCastleTiledMapData.TTileset.Load

  ...
  finally FreeAndNil(I) end;
  
  { Object tilesets may have independend object image files, thus the URL is empty. }
  if Image.URL <> '' then
  begin
    { In case tileset doesn't specify image size,
      testcase: examples/tiled/map_viewer/data/maps/perspective_walls.tmx }
    Image.DetermineSize;

    { Fix Columns if necessary, testcase: examples/tiled/map_viewer/data/maps/desert.tmx }
    if Columns = 0 then
      Columns := Image.Width div TileWidth;

    { Fix TileCount, if it is not found in (old) tsx-files prior to version 0.13 (Aug 2015). }
    if TileCount = 0 then
      TileCount := (Image.Height div TileHeight) * Columns;
  end;

Of course it would much better if the TImage isn't created in the construtor at all.

Now it loads without crashing, but as the object-renderer doesn't know about the tileset image it just draws an rectangle - but at a wrong y-position (bottom-up/vertically flipped):
viewtiledobj1

This is the correct y-position as shown in Tiled:
viewtiledobj2

Here are the tmx files:
tiled-object-test1.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant