Page 1 of 1

Clearing framebuffer - loops randomly stop

Posted: Fri Feb 25, 2022 10:15 am
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!

Re: Clearing framebuffer - loops randomly stop

Posted: Fri Feb 25, 2022 11:28 am
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;"

Re: Clearing framebuffer - loops randomly stop

Posted: Thu Sep 22, 2022 3:39 am
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,