Clearing framebuffer - loops randomly stop

Programming, for all ages and all languages.
Post Reply
Electrical
Posts: 8
Joined: Wed May 27, 2020 8:27 am

Clearing framebuffer - loops randomly stop

Post by Electrical »

Hello! I made a simple function to clear the framebuffer. The problem is that it stops randomly. I tried it in both virtualbox and qemu. What is causing that?

Code: Select all

void renderer_clear(framebuffer_t* fb) {
    
    uint32_t color = 0xff0000ff;
    
    for(size_t y = 0; y < fb->height; y++) {
        
        uint32_t* pix_ptr = fb->base + fb->pps * y;
        
        for(size_t x = 0; x < fb->width; x++) {
            
            *pix_ptr = color;
            pix_ptr++;
            
        }
        
    }
    
}
Screenshots of virtualbox are attached. Thanks in advance!
Attachments
screenshot2.png
screenshot1.png
Electrical
Posts: 8
Joined: Wed May 27, 2020 8:27 am

Re: Clearing framebuffer - loops randomly stop

Post by Electrical »

Fixed it! I had to change "uint32_t* pix_ptr = fb->base + fb->pps * y;" to "uint32_t* pix_ptr = fb->base + fb->pps * y * 4;"
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

Re: Clearing framebuffer - loops randomly stop

Post by devc1 »

You can also simply do a memset with 32 bits as value.
For faster performance (I guess this is mature for you now but however I'll write this so you remember it on the future) : Enable Write Combining, Perform an SIMD Memset (SSE (128 BITS)/AVX (256 BITS)/ AVX-512 (512 BITS). If supported,
Post Reply