Closed Hwan-seok closed 1 year ago
It looks like it tries to render a non isometric game in an isometric way? @jtmcdole
How many tile images do you have in the tiled map? I'm curious if this is hitting a device limit, even though I've tested with 8k textures
It looks like it tries to render a non isometric game in an isometric way? @jtmcdole
I don't think its isometric rendering, I think it's still orthogonal, I've tested isometric with different sized tiles as well. I'd be curious if @Hwan-seok could any of the following:
final atlas = await TiledAtlas.fromTiledMap(component.tileMap.map),
final data = await atlas.atlas.toByteData(format: ImageByteFormat.png);
await File('data.png').writeBytes(data.buffer.asUint8List());
I'm happy to search around for orthogonal tests to kitbash a large map. Does this blow up on Windows?
This is my map settings
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down"
width="112" height="80"
tilewidth="32" tileheight="32"
infinite="0" nextlayerid="66" nextobjectid="241"
>
Has 31 tilesets
Each tileset's tilecount is 100~ 4134 as follows
<tileset firstgid="1" name="some tileset name" tilewidth="32" tileheight="32" tilecount="4134" columns="39">
The sum of tilecount is approximately > 13000
Unfortunately, this is not open source so I cannot explicitly upload it here... But I am ready to figure it out together.
I used macOS and physical devices. Is this answer right for your question?
- write out the TiledAsset image that is attached to the map.
final atlas = await TiledAtlas.fromTiledMap(component.tileMap.map), final data = await atlas.atlas.toByteData(format: ImageByteFormat.png); await File('data.png').writeBytes(data.buffer.asUint8List());
Is this mean that uploading the
data.png
here?
Thanks for the info!
At 8K textures, 32x32 individual tiles would fit about 65536 tiles, which is far less than 13,000. It would be helpful to know what the eventual packed texture is. I suspect that if they are all 39 columns wide, that leads to only 6 atlases packed. per row... and about 2 atlas tall, so 6x2x4134 ~= 49500 tiles still packed. It really depends on the shape of each tileset atlas.
<tileset>
you listed above, I could recreate at least the packed layout. This isn't sharing the images, just the XML layouts.Please excuse me that I am not an expert in game programming. So I have less knowledge about the terms.
..., that leads to only 6 atlases packed. per row... and about 2 atlas tall, so 6x2x4134 ~= 49500 tiles still packed
Sorry, but I cannot understand what exactly this means.
There was some mistake in counting the tilesets. The number of tileset was 41 and the sum of their tilecount is 15130.
<tileset firstgid="1" name="..." tilewidth="32" tileheight="32" tilecount="4134" columns="39">
<tileset firstgid="4135" name="..." tilewidth="32" tileheight="32" tilecount="612" columns="18">
<tileset firstgid="4747" name="..." tilewidth="32" tileheight="32" tilecount="1760" columns="16">
<tileset firstgid="6507" name="..." tilewidth="32" tileheight="32" tilecount="1" columns="1">
<tileset firstgid="6508" name="..." tilewidth="32" tileheight="32" tilecount="252" columns="18">
<tileset firstgid="6760" name="..." tilewidth="32" tileheight="32" tilecount="156" columns="12">
<tileset firstgid="6916" name="..." tilewidth="32" tileheight="32" tilecount="90" columns="10">
<tileset firstgid="7006" name="..." tilewidth="32" tileheight="32" tilecount="88" columns="11">
<tileset firstgid="7094" name="..." tilewidth="32" tileheight="32" tilecount="169" columns="13">
<tileset firstgid="7263" name="..." tilewidth="32" tileheight="32" tilecount="100" columns="10">
<tileset firstgid="7363" name="..." tilewidth="32" tileheight="32" tilecount="100" columns="10">
<tileset firstgid="7463" name="..." tilewidth="32" tileheight="32" tilecount="100" columns="10">
<tileset firstgid="7563" name="..." tilewidth="32" tileheight="32" tilecount="380" columns="20">
<tileset firstgid="7943" name="..." tilewidth="32" tileheight="32" tilecount="209" columns="19">
<tileset firstgid="8152" name="..." tilewidth="32" tileheight="32" tilecount="1416" columns="24">
<tileset firstgid="9568" name="..." tilewidth="32" tileheight="32" tilecount="72" columns="8">
<tileset firstgid="9640" name="..." tilewidth="32" tileheight="32" tilecount="1248" columns="16">
<tileset firstgid="10888" name="..." tilewidth="32" tileheight="32" tilecount="221" columns="13">
<tileset firstgid="11109" name="..." tilewidth="32" tileheight="32" tilecount="221" columns="13">
<tileset firstgid="11330" name="..." tilewidth="32" tileheight="32" tilecount="221" columns="13">
<tileset firstgid="11551" name="..." tilewidth="32" tileheight="32" tilecount="81" columns="9">
<tileset firstgid="11632" name="..." tilewidth="32" tileheight="32" tilecount="81" columns="9">
<tileset firstgid="11713" name="..." tilewidth="32" tileheight="32" tilecount="81" columns="9">
<tileset firstgid="11794" name="..." tilewidth="32" tileheight="32" tilecount="221" columns="13">
<tileset firstgid="12015" name="..." tilewidth="32" tileheight="32" tilecount="221" columns="13">
<tileset firstgid="12236" name="..." tilewidth="32" tileheight="32" tilecount="140" columns="10">
<tileset firstgid="12376" name="..." tilewidth="32" tileheight="32" tilecount="250" columns="10">
<tileset firstgid="12626" name="..." tilewidth="32" tileheight="32" tilecount="630" columns="21">
<tileset firstgid="13256" name="..." tilewidth="32" tileheight="32" tilecount="100" columns="10">
<tileset firstgid="13356" name="..." tilewidth="32" tileheight="32" tilecount="54" columns="6">
<tileset firstgid="13410" name="..." tilewidth="32" tileheight="32" tilecount="486" columns="18">
<tileset firstgid="13896" name="..." tilewidth="32" tileheight="32" tilecount="100" columns="10">
<tileset firstgid="13996" name="..." tilewidth="32" tileheight="32" tilecount="64" columns="8">
<tileset firstgid="14060" name="..." tilewidth="32" tileheight="32" tilecount="99" columns="9">
<tileset firstgid="14159" name="..." tilewidth="32" tileheight="32" tilecount="140" columns="10">
<tileset firstgid="14299" name="..." tilewidth="32" tileheight="32" tilecount="348" columns="12">
<tileset firstgid="14647" name="..." tilewidth="32" tileheight="32" tilecount="100" columns="10">
<tileset firstgid="14747" name="..." tilewidth="32" tileheight="32" tilecount="100" columns="10">
<tileset firstgid="14847" name="..." tilewidth="32" tileheight="32" tilecount="96" columns="8">
<tileset firstgid="14943" name="..." tilewidth="32" tileheight="32" tilecount="88" columns="8">
<tileset firstgid="15031" name="..." tilewidth="32" tileheight="32" tilecount="100" columns="10">
Is this means git HEAD? or something else?
First: Thank you for the report and data!
Running your tileset dimensions through the rectangle packer does show its capable of packing to 8k textures as seen in the bottom image... but either my rendering is wrong or I have a bug / missed test case (totally possible!)
I will try to simulate / reproduce this today on an older pixel phone (either 2xl or 3).
Can I assign this to you @jtmcdole? :)
@jtmcdole No problem! Are there any actions that I can help you with?
Can I assign this to you @jtmcdole? :)
Yes. I still havn't reprod the case yet - but I've been really side tracked. I'm interested if forcing only 4K textures would be the correct solution.
I tested by giving some changes to the size of the bin packer.
The video is from Galaxy Z flip 3.
@Hwan-seok is it the same behaviour on all platforms?
@spydon
On IOS, it immediately crashes with following logs
libc++abi: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc thread #10, name = 'io.flutter.1.raster', stop reason = signal SIGABRT frame #0: 0x00000001b7375b38 libsystem_kernel.dylib
__pthread_kill + 8 libsystem_kernel.dylib
__pthread_kill: -> 0x1b7375b38 <+8>: b.lo 0x1b7375b58 ; <+40> 0x1b7375b3c <+12>: pacibsp 0x1b7375b40 <+16>: stp x29, x30, [sp, #-0x10]! 0x1b7375b44 <+20>: mov x29, sp Target 0: (Runner) stopped. Lost connection to device.
The app immediately crashed after TiledComponent was loaded in the past test. I have some problems with my physical IOS devices currently so I only re-tested on the simulator and YES it also has the problem.
Unfortunately, my project does not contains the web. So I cannot confirm it.
Edit: I also tested in the physical device(IPhone 12 mini) and it immediately crashes with similar logs
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=2098 MB, unused=0x0)
frame #0: 0x000000019926dde0 libdispatch.dylib`voucher_activity_trace_v_2 + 96
libdispatch.dylib`voucher_activity_trace_v_2:
-> 0x19926dde0 <+96>: ldr w8, [x24, #0x610]
0x19926dde4 <+100>: cmn w8, #0x1
0x19926dde8 <+104>: b.eq 0x19926e27c ; <+1276>
0x19926ddec <+108>: str xzr, [sp, #0x58]
Target 0: (Runner) stopped.
@jtmcdole I tested in an isolated environment because possibly the problem is in my project. But the issue remains.
The followings are other maps that I tested and they almost don't have an issue. The FPS became nearly normal.
Edit: It also drops FPS. But just the amount is less. It shows 20~30 FPS.
<tileset firstgid="1" name="meta_tile" tilewidth="32" tileheight="32" tilecount="1" columns="1">
<image source="..." width="32" height="32"/>
</tileset>
<tileset firstgid="2" name="mirasoul" tilewidth="32" tileheight="32" tilecount="322" columns="14">
<image source="..." width="448" height="736"/>
</tileset>
<tileset firstgid="324" name="mirasoul_2" tilewidth="32" tileheight="32" tilecount="210" columns="15">
<image source="..." width="484" height="450"/>
</tileset>
<tileset firstgid="534" name="mirasoul_3" tilewidth="32" tileheight="32" tilecount="130" columns="10">
<image source="..." width="320" height="417"/>
<tileset firstgid="1" name="Room_Builder_32x32" tilewidth="32" tileheight="32" tilecount="8284" columns="76">
<image source="...." width="2432" height="3488"/>
</tileset>
<tileset firstgid="8285" name="music_map_asset_1" tilewidth="32" tileheight="32" tilecount="400" columns="20">
<image source="...." width="640" height="640"/>
</tileset>
<tileset firstgid="8685" name="generic" tilewidth="32" tileheight="32" tilecount="1248" columns="16">
<image source="...." width="512" height="2496"/>
</tileset>
<tileset firstgid="9933" name="basement" tilewidth="32" tileheight="32" tilecount="800" columns="16">
<image source="...." width="512" height="1600"/>
</tileset>
<tileset firstgid="10733" name="meta_tile" tilewidth="32" tileheight="32" tilecount="1" columns="1">
<image source="...." width="32" height="32"/>
</tileset>
<tileset firstgid="10734" name="Modern_Exteriors_Complete_Tileset_32x32" tilewidth="32" tileheight="32" tilecount="4134" columns="39">
<image source="...." width="1248" height="3392"/>
</tileset>
<tileset firstgid="14868" name="fishing" tilewidth="32" tileheight="32" tilecount="432" columns="16">
<image source="...." width="512" height="864"/>
</tileset>
<tileset firstgid="15300" name="hospital" tilewidth="32" tileheight="32" tilecount="1760" columns="16">
<image source="...." width="512" height="3520"/>
</tileset>
<tileset firstgid="17060" name="cafe_map_asset" tilewidth="32" tileheight="32" tilecount="841" columns="29">
<image source="...." width="958" height="958"/>
</tileset>
<tileset firstgid="17901" name="UI_32x32" tilewidth="32" tileheight="32" tilecount="252" columns="18">
<image source="...." width="576" height="448"/>
</tileset>
<tileset firstgid="18153" name="exterior" tilewidth="32" tileheight="32" tilecount="612" columns="18">
<image source="...." trans="ff00ff" width="576" height="1088"/>
</tileset>
<tileset firstgid="18765" name="desk_asset_2" tilewidth="32" tileheight="32" tilecount="100" columns="10">
<image source="...." width="320" height="320"/>
</tileset>
<tileset firstgid="18865" name="celeb_light_h_3" tilewidth="32" tileheight="32" tilecount="100" columns="10">
<image source="...." width="320" height="320"/>
</tileset>
<tileset firstgid="18965" name="board_n" tilewidth="32" tileheight="32" tilecount="100" columns="10">
<image source="...." trans="ff00ff" width="320" height="320"/>
</tileset>
This is for memory usage. Seems memory usage is significantly increased. Also, the graph shows some inclination.
Based on
stop reason = EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=2098 MB, unused=0x0)
it appears that the problem is that the device is running out of memory. Though normally this shouldn't trigger a crash, it probably indicates some problem in the underlying Flutter framework or even lower. So, if there was a way to create an MRE, it would be great to post it to Flutter's repo.
As far as fixing the problem, it might be possible to do it on our side one way or another:
TiledAtlas
contains a clone()
method which creates a copy of the atlas image -- I'm not sure why we decided such copy was necessary, but perhaps it can be avoided after all. At the very least I'd suggest adding a simple print
statement inside that method, so that we can see how often the atlas is being copied. If it happens on every game tick for whatever reason, then it would be a big problem...TileAtlas.fromTiledMap()
constructor, where it doesn't check that the rect
returned from RectangleBinPacker
has non-zero size. In fact, there is no check that the size of loaded image corresponds to the size of TiledImage
-- this could potentially lead to the corruption of the resulting atlas, if we're copying image of incorrect size.I finally managed to find what was causing this. This is strongly related to "flips". I mentioned the flips are impacting performance in #1614 and #1714. Here you can see the atlas is expanded to 2x width size when using flips https://github.com/flame-engine/flame/blob/7662118d14701a08ed07b83d31394f29e98ec7f0/packages/flame/lib/src/sprite_batch.dart#L215-L236 Even though the atlas made by RectangleBinPacker has 8k texture, the SpriteBatch makes it to 16k texture if flip exists.
To prove flips are causing this, I replaced the following line to final flips = SimpleFlips.fromFlips(Flips.defaults());
and the problem was gone.
https://github.com/flame-engine/flame/blob/7662118d14701a08ed07b83d31394f29e98ec7f0/packages/flame_tiled/lib/src/renderable_layers/tile_layer.dart#L112
Would you assign this to me @spydon?
Well researched @Hwan-seok, assigned it to you!
@Hwan-seok can this issue be closed?
@spydon TiledAtlas makes the bigger images for SpriteBatch, so I think this issue cannot be fixed by Flame itself but https://github.com/flutter/flutter/issues/120215 will be. Please mark this as a Flutter issue. Thanks!
Current bug behaviour
After bc2db2b17af997fd529800abe0124b0f8918295f, tiled map performance & rendering issue came out. FPS drops to 0~10s and it renders inappropriate tile.
Before bc2db2b17af997fd529800abe0124b0f8918295f
https://user-images.githubusercontent.com/38072762/194514541-f87f3039-a1d3-4b01-a1a7-6dfb9a577a64.mp4
After bc2db2b17af997fd529800abe0124b0f8918295f
https://user-images.githubusercontent.com/38072762/194514568-d22cb2bf-a890-4613-961f-70b642242430.mp4
__pthread_kill + 8 libsystem_kernel.dylib
__pthread_kill: -> 0x1b7375b38 <+8>: b.lo 0x1b7375b58 ; <+40> 0x1b7375b3c <+12>: pacibsp 0x1b7375b40 <+16>: stp x29, x30, [sp, #-0x10]! 0x1b7375b44 <+20>: mov x29, sp Target 0: (Runner) stopped. Lost connection to device.Expected behaviour
Renders right tile and fixes the performance.
Flutter doctor output
More environment information