Crash when using assets/game.love

Issue #8 resolved
Pavol Rusnak created an issue

I tried to bundle my Love code via assets/game.love and encountered a crash. Game works when I unpack game.love to /sdcard/lovegame and app loads resources from there ...

Adb logcat output is attached:

Comments (7)

  1. Martin Felis repo owner

    How big is the file?

    In the filesystem module I copy game.love from the assets into the app internal storage and then load it using physicfs. Currently I copy the whole file into a buffer which could fail for big files.

    If you feel adventurous you can try to adjust the code to copy the file in smaller chunks. Otherwise I can provide a patch tomorrow.

  2. Pavol Rusnak reporter
    I/SDL/APP (27505): Found game.love in assets. Size: 1559599
    

    which is the correct size.

  3. Pavol Rusnak reporter

    I see. Why do you need to copy game.love from assets to InternalStorage and use it from there? Isn't it possible to use directly?

    Btw, this small hack/workaround fixed the issue, but I agree it would be better to copy in smaller chunks. Or even better to avoid copying completely if possible.

    --- a/jni/love/src/modules/filesystem/physfs/Filesystem.cpp
    +++ b/jni/love/src/modules/filesystem/physfs/Filesystem.cpp
    @@ -133,7 +133,7 @@ namespace
                    return false;
                }
    
    -           char data_buffer[file_size + 1];
    +           char *data_buffer = (char *)malloc(file_size + 1);
                size_t bytes_read = asset_game_file->read(asset_game_file, data_buffer, sizeof(char), (size_t) file_size);
                data_buffer[bytes_read] = '\0';
    
    @@ -155,6 +155,7 @@ namespace
    
                    asset_game_file->close(asset_game_file);
                    storage_game_file->close(storage_game_file);
    +               free(data_buffer);
    
                    SDL_Log ("Copying of asset game to internal storage %s successful!", internal_game_file.c_str());
    
  4. Martin Felis repo owner

    Accessing Android assets from C has to go through JNI and PhysicFS does not have support for it. Internal and external storage can be accessed using standard io, hence the copying.

    Avoiding the copying would be great but too tricky for now.

    Good to hear that your fix works. I will add copying in chunks the next few days.

  5. Log in to comment