At the very beginning of Handmade Hero, Casey allocates some memory for his back buffer using VirtualAlloc() which he then passes to CreateDIBSection() in order to create a DIB. After spending sometime debugging his code, I've found out that the VirtualFree() function fails and doesn't free up the back buffer. Correct me if I'm wrong but I think the reason for that is because CreateDIBSection() actually changes the address of the allocated buffer and this new address is what being passed to VirtualFree() instead of the old one that was generated by VirtualAlloc(), therefore - causing it to fail.
To make a long story short, I've managed to solve this problem be getting rid of VirtualAlloc() and VirtualFree(), and instead, pass an unallocated buffer straight to CreateDIBSection() and freeing it up later on using DeleteObject().
My question to you is: Is it even necessary to make any sort of allocation for the buffer prior to using CreateDIBSection(), or does this function take care of it for me?
(The doc for CreateDIBSection() states that "If hSection is NULL, the system allocates memory for the DIB.").