Hey! raylib forum is closing!

After a year with not much movement in the forum I decided to close it.

The cost of maintaining the hosting is a bit high for the usage of the platform, updating the forum and managing it is also a bit cumbersome and the truth is that I'm already trying to maintain multiple other networks pretty more active than this forum.

I'll recommend you to move to the other raylib networks:

- For a forum style, use Reddit: https://www.reddit.com/r/raylib/
- For direct messaging and questions, use Discord: https://discord.gg/VkzNHUE
- To report issues, use GitHub: https://github.com/raysan5/raylib

- Also, remember you can contact me personally on Twitter: https://twitter.com/raysan5 or directly by mail to ray[at]raylib.com

If you feel generous, you can also contribute to the project on my Patreon: https://www.patreon.com/raylib

Thanks to you all for joining the project and help to improve it with your questions. Keep it up! :)

Best Regards,


PD. Closing will be effective by October 31th.

IsGamepadButtonReleased & IsGamepadButtonReleased unexpected behavior

edited October 2016 in raylib: core
Hi Ray! While working on an input abstraction layer module for my game, I noticed some unexpected behavior from the IsGamepadButtonPressed and IsGamepadButtonReleased functions. This program demonstrates the issues:

#include "raylib.h" int screen_width = 800; int screen_height = 600; void main(){ InitWindow(screen_width, screen_height, "Gamepad button booleans test"); bool isGBD = false; int isGBDi = 0; bool isGBP = false; int isGBPi = 0; bool isGBR = false; int isGBRi = 0; SetTargetFPS(1); while (!WindowShouldClose()){ // Expected: returns true iff the button is being pressed // Actual: as expected isGBD = IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_A); isGBDi = isGBD ? 1 : 0; // Expected: returns true only on the frame that the button is first pressed // Actual: // Returns true as long as button is being pressed, // EXCEPT on the first frame that it's pressed isGBP = IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_A); isGBPi = isGBP ? 1 : 0; // Expected: returns true only if the button was released that frame // Actual: returns true as long as the button is not being pressed isGBR = IsGamepadButtonReleased(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_A); isGBRi = isGBR ? 1 : 0; BeginDrawing(); ClearBackground(RAYWHITE); DrawText(FormatText("Is A down: %i", isGBDi), 50, 50, 30, ORANGE); DrawText(FormatText("Is A pressed: %i", isGBPi), 50, 100, 30, ORANGE); DrawText(FormatText("Is A released: %i", isGBRi), 50, 150, 30, ORANGE); EndDrawing(); } CloseWindow(); }

I tested and reproduced this on the following gamepads:
Xbox One S
Xbox One
Xbox 360
SteelSeries Stratus XL
Logitech F310

This is not the results that these functions should return, right?

Thanks as always for your help ~



  • Sorry, the title is a typo, I meant "IsGamepadButtonPressed and IsGamepadButtonReleased"
  • Hi wly_cdgr!

    I took a quick look to this code and I'm pretty sure those two functions are wrong... Need to review them! The issue happens when you use both functions one after the other...

    Just note that you don't need to use isGBDi-isGBPi-isGBRi, actually a 'bool' in C is already an 'int' and 'false - true' is the same as 0 - 1.

    I'll try to correct this issue in the following days.
  • No rush, just wanted to give you a heads up. Thanks!
  • Hi wly_cdgr! Just an update on this issue:

    Effectively, it's wrong. I coded this part long ago (more than two years ago) and despite I redesigned it some time later for Raspberry Pi, I didn't change desktop platforms code (Windows, Linux, OSX). It requires a complete review.

    I'm already working on it, hopefully it will be ready for next week. At the same time, I'm also adding support for up to four gamepads and some additional functionality like checking the gamepad name id.

    It will be ready for the upcoming raylib 1.6.
  • Hey! Already reviewed gamepad system! Corrected the issue and added support for up to 4 gamepads! Also added new function to get controller name id.

    Still need some testing but already uploaded changes in latest develop branch in github (https://github.com/raysan5/raylib/tree/develop).

    I'm preparing a complete sample to demonstrate gamepad functionality...
  • Hi Ray! Amazing, thanks! The controller name retrieval function will come in very handy for making sure that the controls work correctly and have the same mapping whatever gamepad the player is using. Given that so many gamepads have the same button and trigger layouts but different glfw mappings, I'm looking forward to using that to create a little abstraction layer to let client ask stuff like "is the bottom face button pressed (whether that's A, X, or whatever else depending on controller brand) ?".

    Quick thing I noticed in the latest commit - looks like the new code in IsGamepadButton* could end up accessing an out of bounds array index if user accidentally or maliciously passes in a bad value for 'button' param?

    Thanks as always!
  • Hey wly_cdgr! Yes, you're right! Button could be out-of-bounds! I forgot about malicious users! :P Corrected in commit: https://github.com/raysan5/raylib/commit/9e285d8dc33a5a18eeb154c69b04de1c1358678d

    I thought the same about the controller name retrieval! I'm preparing a sample just to show that functionality, depending on controller, show a controller image or another (PS3 - XBOX360) with already mapped inputs... maybe in a future I can add support for some standard controllers, I mean, with automatic input mapping.
  • Update: I've been testing changes and there was a bug, now everything works ok (uploaded to github, available for raylib 1.6).

    I noticed that depending on Windows version and gamepad, axis get mangled and must be reassigned...
Sign In or Register to comment.