Ch4ozz wrote:Looks like your stack is inside the buffer.
Find out if the picture buffer itself was corrupted or if its the vram
omarrx024 wrote:alexfru made it there before me; I was just going to say that it's most likely memory corruption.
EDIT: Notice that the BMP image inside your OS is horizontally inverted; if you'd like BMP parsing code, I have a function for that (only works on 24-bit BMP images, but can easily be extended.)
omarrx024 wrote:Memory corruption? Using memory after freeing (including using automatic/local arrays after going out of the function scope where they're defined)?
Hi, I think it's not due to memory corruption of the picture buffer, because it's allocated by a heap allocator and does not overlap with the stack, and I never free the heap.
Also, I compared the vram and the picture immediately after the picture buffer was copied to the vram, they're not the same.
(since the actual picture pixels in bmp file are reversed, I've to copy them in the reversed direction)
Code: Select all
void weird_memcpy(void * dest, void * src, uint32_t count) {
char * p1 = dest, * p2 = src;;
while(count-- > 0) {
memcpy(p1, p2-3, 3);
p1 = p1 + 3;
p2 = p2 - 3;
}
}
void bitmap_display(bitmap_t * bmp) {
if(!bmp) return;
void * data = bmp->image_bytes;
char * image = data;
char * screen = (char*)0xfc000000;
weird_memcpy(screen, data + bmp->width * bmp->height * 3, bmp->width * bmp->height);
// Compare the video ram and the data
uint32_t count = bmp->width * bmp->height * 3;
char * p1 = screen, * p2 = image + bmp->width * bmp->height * 3;
while(count-- > 0) {
char first = *(p2-3);
char second = *(p2-2);
char third = *(p2-1);
if(first != *p1)
printf("no no no\n");
if(second != *(p1+1))
printf("no no no\n");
if(third != *(p1+2))
printf("no no no\n");
p1 = p1 + 3;
p2 = p2 - 3;
}
printf("yeah yeah yeah\n");
}