Skip to content

Commit 41b0238

Browse files
committed
- also handle missing file in case of the mappings (even if it should never occur, since it's non fatal it's not a bad idea to check it
1 parent 5024d18 commit 41b0238

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/input/joystick_input.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <algorithm>
1313
#include <exception>
14+
#include <filesystem>
1415
#include <spdlog/spdlog.h>
1516

1617

@@ -120,13 +121,17 @@ void input::JoyStickInputManager::discover_devices(std::vector<std::unique_ptr<I
120121

121122
const auto mappings_file = utils::get_assets_folder() / "mappings" / "gamecontrollerdb.txt";
122123

123-
const auto mapped_number = SDL_GameControllerAddMappingsFromFile(mappings_file.string().c_str());
124-
125-
if (mapped_number < 0) {
126-
// this is just a warning, no need to abort here, since we just have less mappings
127-
spdlog::warn("Failed to add new Controller mappings: {}", SDL_GetError());
124+
if (not std::filesystem::exists(mappings_file)) {
125+
spdlog::warn("Mappings file doesn't exist: {}", mappings_file.string());
128126
} else {
129-
spdlog::debug("Added {} new Controller mappings!", mapped_number);
127+
const auto mapped_number = SDL_GameControllerAddMappingsFromFile(mappings_file.string().c_str());
128+
129+
if (mapped_number < 0) {
130+
// this is just a warning, no need to abort here, since we just have less mappings
131+
spdlog::warn("Failed to add new Controller mappings: {}", SDL_GetError());
132+
} else {
133+
spdlog::debug("Added {} new Controller mappings!", mapped_number);
134+
}
130135
}
131136

132137

0 commit comments

Comments
 (0)