Skip to content

Conversation

clang-clang-clang
Copy link
Contributor

This PR removes a main thread IO to avoid ANR; allows Android to use mmap to load Lua code packages; and an additional Rtt_ASSERT correction.

Remove a main thread IO

There is a risk of ANR when loadExpansionFiles() in the main UI thread, so the main UI thread reading is changed to the main thread modifying the state, and the GLThread is used to read.

Android to use mmap to load Lua code packages

This PR allows Android to load the Lua code package (resource.car) like other platforms, using mmap, to reduce runtime memory by extracting the resource.car at first launch. It doesn't need to be uncompressed every launch, so it also positively affects startup time.

During the public beta phase, it was observed that some models showed the situation where AssetManager prematurely returns -1 when decompressing resources (approximately 0.3%). This issue was resolved by improving the accuracy, reliability, and usability of the extractAssetFile() method (at least this exception is no longer observed online). The worstcase scenario here is the same as before, when the getBytesFromFile() method failed to load the code package into memory all at once, resulting in a black screen after startup, but usually, it will not happen again when restarting the App.

Rtt_ASSERT correction

Additionally, while debugging other issues, I found an Rtt_ASSERT that could not be false. After correcting it to match the context, I guess it's not allowed to move DisplayObject from the Orphanage() group to the Orphanage() group again, that is, to removeSelf repeatedly.

Any suggestions are welcome. Thank you.

@Shchvova
Copy link
Contributor

This is awesome. Earlier versions of Android had issues with mmap. I see that you have it in the wild and it seems to work now?

@clang-clang-clang
Copy link
Contributor Author

mmap works like a charm.

Earlier versions of Android had issues with mmap.

Are there specific problem records for early versions? We have covered the API 15, which is the minimum supported by Solar2D. Since the launch of mmap, we have never observed mmap errors in the location of loading resource.car, but it may not be sufficient to reflect compatibility issues.

@Shchvova Shchvova merged commit aa4140d into coronalabs:master Mar 13, 2024
@clang-clang-clang clang-clang-clang deleted the android-mmap-resource_car branch March 13, 2024 07:36
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

Successfully merging this pull request may close these issues.

2 participants