Skip to content

[BUG] fopen crashes the game when $HOME/.config/notblood/{ModDir} is not present #984

@P1roks

Description

@P1roks

Hello. I was trying to play the newly released Death Wish 2.0 expansion using this sourceport, but when I tried to save, the following error from loadsave.cpp was getting thrown:

    hSFile = fopen(saveFileName, "wb");
    if (hSFile == NULL)
        ThrowError("File error #%d creating save file.", errno);

I've done a bit of digging and came to the following conclusions:
1.I like to keep my blood installation tidy, thus I've made a separate directory for it called dw which lived inside the game directory
2.I had a simple bash script written, which launched the game in the following way: nblood -game_dir dw -ini dw.ini, which led to the g_modDir being set inside the C++ program and later inside the nblood.cfg config file
3.When I tried to save, the macro G_ModDirSnprintf set the savePath to dw/game0000.sav (or some similar value)
4.fopen was called with $HOME/.config/nblood/dw/game000.sav but since dw file didn't exist, it returned NULL (fopen cannot create directories, only files) and led to the crash happening

The fix to this issue should be to simply ensure that the parent directory exists when calling the fopen (or to use some other function that can handle creating them). For now, I've simply created $HOME/.config/nblood/dw directory and saving works now, but this is a workaround that will require me to create similar dir for every new modpack that I play, which is quite annoying.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions