k4zmu2a / SpaceCadetPinball

Decompilation of 3D Pinball for Windows – Space Cadet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build failing on Xubuntu 18.04

krishean opened this issue · comments

When compiling the master branch on Xubuntu 18.04 the build has been failing since commit d99fbb0 with the error:

SpaceCadetPinball/options.cpp: In member function ‘std::__cxx11::string GameInput::GetInputDescription() const’:
SpaceCadetPinball/options.cpp:507:52: error: ‘SDL_CONTROLLER_BUTTON_TOUCHPAD’ was not declared in this scope
   if (Value >= SDL_CONTROLLER_BUTTON_A && Value <= SDL_CONTROLLER_BUTTON_TOUCHPAD)
                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SpaceCadetPinball/options.cpp:507:52: note: suggested alternative: ‘SDL_CONTROLLER_BUTTON_MAX’
   if (Value >= SDL_CONTROLLER_BUTTON_A && Value <= SDL_CONTROLLER_BUTTON_TOUCHPAD)
                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                    SDL_CONTROLLER_BUTTON_MAX
CMakeFiles/SpaceCadetPinball.dir/build.make:268: recipe for target 'CMakeFiles/SpaceCadetPinball.dir/SpaceCadetPinball/options.cpp.o' failed
make[2]: *** [CMakeFiles/SpaceCadetPinball.dir/SpaceCadetPinball/options.cpp.o] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/SpaceCadetPinball.dir/all' failed
make[1]: *** [CMakeFiles/SpaceCadetPinball.dir/all] Error 2
Makefile:135: recipe for target 'all' failed
make: *** [all] Error 2
Done.

I looked into it, and the version of SDL2 that is in the 18.04 repo (2.0.8, quite old) has a very different SDL_GameControllerButton enum than more modern versions of SDL2.

In SDL2 2.0.8:

typedef enum
{
    SDL_CONTROLLER_BUTTON_INVALID = -1,
    SDL_CONTROLLER_BUTTON_A,
    SDL_CONTROLLER_BUTTON_B,
    SDL_CONTROLLER_BUTTON_X,
    SDL_CONTROLLER_BUTTON_Y,
    SDL_CONTROLLER_BUTTON_BACK,
    SDL_CONTROLLER_BUTTON_GUIDE,
    SDL_CONTROLLER_BUTTON_START,
    SDL_CONTROLLER_BUTTON_LEFTSTICK,
    SDL_CONTROLLER_BUTTON_RIGHTSTICK,
    SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
    SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
    SDL_CONTROLLER_BUTTON_DPAD_UP,
    SDL_CONTROLLER_BUTTON_DPAD_DOWN,
    SDL_CONTROLLER_BUTTON_DPAD_LEFT,
    SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
    SDL_CONTROLLER_BUTTON_MAX
} SDL_GameControllerButton;

In the latest version of SDL2 2.26.3:

typedef enum
{
    SDL_CONTROLLER_BUTTON_INVALID = -1,
    SDL_CONTROLLER_BUTTON_A,
    SDL_CONTROLLER_BUTTON_B,
    SDL_CONTROLLER_BUTTON_X,
    SDL_CONTROLLER_BUTTON_Y,
    SDL_CONTROLLER_BUTTON_BACK,
    SDL_CONTROLLER_BUTTON_GUIDE,
    SDL_CONTROLLER_BUTTON_START,
    SDL_CONTROLLER_BUTTON_LEFTSTICK,
    SDL_CONTROLLER_BUTTON_RIGHTSTICK,
    SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
    SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
    SDL_CONTROLLER_BUTTON_DPAD_UP,
    SDL_CONTROLLER_BUTTON_DPAD_DOWN,
    SDL_CONTROLLER_BUTTON_DPAD_LEFT,
    SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
    SDL_CONTROLLER_BUTTON_MISC1,    /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button */
    SDL_CONTROLLER_BUTTON_PADDLE1,  /* Xbox Elite paddle P1 */
    SDL_CONTROLLER_BUTTON_PADDLE2,  /* Xbox Elite paddle P3 */
    SDL_CONTROLLER_BUTTON_PADDLE3,  /* Xbox Elite paddle P2 */
    SDL_CONTROLLER_BUTTON_PADDLE4,  /* Xbox Elite paddle P4 */
    SDL_CONTROLLER_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
    SDL_CONTROLLER_BUTTON_MAX
} SDL_GameControllerButton;

Commit d99fbb0 added SDL_CONTROLLER_BUTTON_TOUCHPAD which does not exist in the enum of the old version of SDL2, but SDL_CONTROLLER_BUTTON_MAX does exist in both versions (and is also suggested as a possible fix in the build error message.)

I suggest changing line 565 in options.cpp from

if (Value >= SDL_CONTROLLER_BUTTON_A && Value <= SDL_CONTROLLER_BUTTON_TOUCHPAD)

to

if (Value >= SDL_CONTROLLER_BUTTON_A && Value < SDL_CONTROLLER_BUTTON_MAX)

I tested out compiling with this change and it successfully builds for me.

It is my fault, I failed to account for SDL version differences.
Applied suggested fix.

Builds fine from master now, thank you! And no need to apologise, it was an easy mistake to make.