I’m trying to load bunch of images from zip file in for for loop like this:
if (plugin.data.exists(pathTop)){
var textureTop = BitmapData.fromBytes(ByteArray.fromBytes(plugin.data.get(pathTop).data));
tempTerrainTexturesTop.set(terrainType.name, textureTop);
}
which crashes after some images are loaded, when using cpp.vm.Thread. When it’s called from main thread, it works fine. Mac native target.
Thanks. One more question – where from my application can I use things like BitmapData.fromBytes? The only place I found yet is ENTER_FRAME event handler and similar.
Should be able to do it anywhere in the main thread,
but in the end it’ll end up in a enter frame event as only possible space for any code (with the exception of the static main function of your main class).
I believe we should use threads if you use Assets.loadBitmapData, I would be interested if this works for you?
This doesn’t for ZIP contents, though (for a long time) I think support for asset packing could be integrated in the Lime tools.
If you are doing it outside of Assets, perhaps you could use a Lime ThreadPool or BackgroundWorker to load the bytes, then use BitmapData.fromBytes in the main thread?
EDIT: The error actually appears to related to HXCPP garbage collection running in the wrong thread. I guess this actually comes back to use needing to come up with a thread-safe GL finalizer (and is not triggered by GL code in the bitmap data load, but just that the allocation there triggers GC activity)
Yeah, you are probably right. I was working on it today and I get crashes in almost every part of my threaded code where lot of temporary objects is created. Even creating simple objects like Point (with 2 integer variables and nothing else) crashes:
while I do absolutely nothing with graphics in this thread. Any suggested approach I should take? I’d really need this fixed and I don’t have any idea what to do.
Now I’m creating new threads from OpenFL events (like ADDED_TO_STAGE). Would it help to create threads from somewhere else, so GC in them won’t trigger GL finalizer? If yes, where in my code can I do that?
I believe I may have this resolved, but I would appreciate your help in testing and confirming if it is working properly. Check out the issue for a link to a development build with the changes