Open pathunstrom opened 3 years ago
This may need to be run several times to suss out threading bugs.
Thanks past me for noting this and trying to write a test to induce this.
Present us now have to debug multi-threaded code.
Interestingly, the problem seems to be that the "target.png" is finished loading, before the three delayed images have started loading. (So surprisingly it seems that the problem does not arise due to the sleep
) Therefore the loading screen, thinks it has loaded all 1 of 1 images and thus continues to the quitter screen.
You could fix it by starting the threadpool later, after all AssetLoading jobs have been submitted. Or maybe better not using the total_queued in the event, but instead look at the global ThreadPool._finished
from the LoadingScene.on_asset_loaded
.
Also the DelayedThreadExecutor._finish
is run from the worker threads, which also touch the _finished and _started variables. It's read only, so it shouldn't be too bad, but it could lead to race conditions.
Edit: fix typo's
New assets can be loaded at any time. And I'd really rather that the loading scene not reach into the internals of the asset loading system.
You could maybe register assets, that you would want to wait on in the loading screen?
Also calling the DelayedThreadExecutor._finish
on the main thread might work. Or checking finished jobs in the main loop?
Or, maybe not use the data in the AssetLoaded event, but instead in on_asset_loaded
, check if all the assets in the next scene are loaded.
You could maybe register assets, that you would want to wait on in the loading screen?
Gotta make sure you both reference the asset and then pre-declare it for the loading screen? And then you forget to update one of the two places.
Also calling the DelayedThreadExecutor._finish on the main thread might work. Or checking finished jobs in the main loop?
I mean, it's never actually finished, just idle. Again, new, previously unknown assets can be referenced at any time.
Or, maybe not use the data in the AssetLoaded event, but instead in on_asset_loaded, check if all the assets in the next scene are loaded.
How do you make that list?
I'm just spitballing here, I don't actually know what would make most sense in this case.
Gotta make sure you both reference the asset and then pre-declare it for the loading screen?
It would be difficult, because asset classes are not instantiated until the scenes are instantiated.
How do you make that list?
You could use meta classes, similar to how SQLAlchemy ORM is used. But I don't know if that would work with the current syntax.
ppb commit: b2eee07a7f0ea OS Windows 10 Python 3.8.6
Output:
Some kind of race condition I think? It's the assert failing.