Log in to reply

Loading images in another thread?

  • While adding image support for a mod, I came across performance problems when loading images. (on every menu open). Opening and closing a bunch of files is slow - of course. I tried to remedy this by doing it in another thread. This made me need to split up my image reading and my createTexture since createTexture can't be called in another thread:

    // Create texture
    //	texFileName	- texture file name, it's best to specify full texture path and use PNG textures
    //	returns	internal texture id
    //	Texture deletion is performed automatically when game reloads scripts
    //	Can be called only in the same thread as natives
    IMPORT int createTexture(const char* texFileName);

    All good, done that, but at menu load my game still freezes for a half second. After being rather confused, I found out that createTexture itself causes this. Is there any way I can keep my game fast while still creating textures?

    Source code

    It's just script.cpp that has the threading stuff in it. resolveImgs2() is where createTexture() is used. checkThread() checks if a task was done.

    With 22 images in my folder, it's very noticeable. As in, the game freezes a bit after the menu is drawn.

    Edit - Seems like I had two duds, two 2MB PNGs. After resizing and JPG-ing them, the problem was less. Then I also just made it check for existing textures before calling createTexture again, and it now opens smoothly while still detecting newly added images. The initial startup is still pretty slow sadly, as it can add 0.5 seconds of freeze when all textures are created.

Log in to reply

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.