raylib: [core] First keyboard input when running causes drawing to pause for very brief time.

Latest raylib from brew.

Im not doing anything intensive at all. I have 100 structs that are drawn using DrawRectangleV() and do nothing more than move from top to bottom and reset back to top once at the bottom. When pressing any key on the keyboard for the first time, it causes the small moving rectangles to pause for a brief time. Maybe 10ms? Doesn’t happen anymore after the first key press until re-launching the game.

I can try and record a video if needed. Im running the latest macos.

Heres my very simple c file.

#include <raylib.h>

//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------

#define A_COUNT(x)  (sizeof(x) / sizeof((x)[0]))

#define SCREEN_WIDTH                    960
#define SCREEN_HEIGHT                   640

#define MAX_STARS                       100
#define MAX_STAR_SIZE                   8
#define MIN_STAR_SIZE                   4

//------------------------------------------------------------------------------
// Types and Structures Definition
//------------------------------------------------------------------------------

typedef struct str_star {
    
    Vector2 position;
    Vector2 size;
    float speed;
    Color color;
    
} str_star;

//------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------

int main()
{
    
    // Initialization
    //--------------------------------------------------------------------------
    
    SetConfigFlags(FLAG_VSYNC_HINT);
    
    InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Test Raylib");
    
    SetTargetFPS(60);
    
    str_star stars[MAX_STARS];
    
    // Init Stars
    for (int i = 0; i < MAX_STARS; i++)
    {
        
        float x = GetRandomValue(0, SCREEN_WIDTH);
        float y = GetRandomValue(0, SCREEN_HEIGHT);
        float size = GetRandomValue(MIN_STAR_SIZE, MAX_STAR_SIZE);
        int r  = GetRandomValue(0, 255);
        int g  = GetRandomValue(0, 255);
        int b  = GetRandomValue(0, 255);
        
        stars[i].position = (Vector2) { x, y };
        stars[i].size = (Vector2) { size, size };
        stars[i].color = (Color) { r, g, b, 255 };
        stars[i].speed = size;
        
    }
    
    // Main game loop
    //--------------------------------------------------------------------------
    
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        
//        if (IsKeyDown(KEY_SPACE))
//        {
//            // First time I press space, the moving stars stop for a breif period.
//            // doesnt happen again after the first key input.
//        }
        
        
        // Update
        //----------------------------------------------------------------------
        
        for (int i = 0; i < MAX_STARS; i++)
        {
            
            stars[i].position.y += stars[i].speed;
            
            if (stars[i].position.y > SCREEN_HEIGHT)
            {
                
                float x = (float)GetRandomValue(0, SCREEN_WIDTH);
                stars[i].position = (Vector2) { x, 0 };
                
            }
            
        }
        
        //----------------------------------------------------------------------
        
        // Draw
        //----------------------------------------------------------------------
        
        BeginDrawing();
        
        ClearBackground(BLACK);
        
        DrawFPS(10, 10);
        
        for (int i = 0; i < MAX_STARS; i++)
            DrawRectangleV(stars[i].position, stars[i].size, stars[i].color);
        
        EndDrawing();
        
        //----------------------------------------------------------------------
    }
    
    // De-Initialization
    //--------------------------------------------------------------------------
    
    CloseWindow();
    
    return 0;
    
}

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

I’m sorry to say I’m experiencing this issue too (some 6 years later!), but only when the app is launched with gdb. If I just run the compiled app without the debugger connected, it’s fine. Im on MacOS Ventura M2 chipset and I’ve confirmed it also happens with the code above, as well as my own app.

Hey @ismyhc, that’s really weird… I liked to track that kind of crazy issues but unfortunately I don’t have enough time at this moment.

I’m closing the issue, feel free to reopen it if you consider it necessary.