Let’s say I have a function that creates Tiles from BitmapData, the gist of which is like:
var batch : h2d.SpriteBatch;
var bitmaps : Array<BitmapData>;
function make_tiles() {
for( bdata in bitmaps ) {
batch.add( new BatchElement( Tile.fromBitmap( bdata ) ) );
}
}
If I call this function, for example, in App::init()
or App::update()
(just once) etc. it will work fine, it will create all the Tiles, the only issue is that application will freeze for a second or two while this loop is doing it’s work.
I tried to run this in a Thread
with Thread.create(make_tiles)
but that fails with:
SIGNAL 11
h3d.impl.MemoryManager.allocTexture(h3d/impl/MemoryManager.hx:258)
h3d.mat.Texture.alloc(h3d/mat/Texture.hx:122)
h3d.mat.$Texture.__constructor__(h3d/mat/Texture.hx:113)
h3d.mat.$Texture.fromBitmap(h3d/mat/Texture.hx:413)
h2d.$Tile.fromBitmap(h2d/Tile.hx:368)
Main.create_tiles(Main.hx:83)
sys.thread._Thread.$HaxeThread.~create.0(/usr/share/haxe/std/hl/_std/sys/thread/Thread.hx:131)
/usr/local/bin/hl: line 3: 24445 Segmentation fault (core dumped) hl.orig "$@"
no matter where I do Thread.create()
: in init()
, update()
, in WaitEvent::waitUntil()
etc.
The question: is there a way (maybe not Thread
but something else) where I can start some long processing (like in this example, creating a bunch of Tiles) in a way that does not block entire Heaps application?