#166605 - albinofrenchy - Wed Feb 11, 2009 3:12 pm
I'm encountering weird artifacts when I redraw the screen. In general it is only there for a split second, but I actually need to READ from the memory buffer of the screen, so the corruption is something I have to fix.
Here is my initialization of the video stuff:
The variable 'drawSub' is 'true'.
Later on, I find the relevant buffers and read parts in via
Where R is a 'box' where I want to reuse the screen to copy to a buffer. dst is an appropriately sized buffer. After a bit more rendering to dst, I throw all of dst onto the buffer with:
Where image = dst; and 'main'/'sub' are found the same way I found 'src' and 'src2' up above.
Is this all correct? It looks like something is writing a datastructure to my VRAM, but surely this is disallowed in general right?
If you want to see this bug in action, grab the release build and open a pdf then scroll around. Source code is available on that same page if you want to look at it in more detail.
As always, Any help on this is appreciated!
Last edited by albinofrenchy on Sat Feb 14, 2009 2:32 pm; edited 1 time in total
Here is my initialization of the video stuff:
Code: |
powerOn(POWER_ALL); videoSetMode(MODE_5_2D); vramSetBankA(VRAM_A_MAIN_BG); u16* sub_buffer; if(drawSub){ videoSetModeSub(MODE_5_2D); vramSetBankC(VRAM_C_SUB_BG); bg_sub = bgInitSub(2, BgType_Bmp16, BgSize_B16_256x256,0,0); sub_buffer = (u16*)bgGetGfxPtr(bg_sub); } bg = bgInit(2, BgType_Bmp16, BgSize_B16_256x256,0,0); u16* buffer = (u16*)bgGetGfxPtr(bg); for(int iy = 0; iy < 192; iy++) for(int ix = 0; ix < 256; ix++) { buffer[ix + iy * 256] = ARGB16(1,31,0,0); if(drawSub){ sub_buffer[ix + iy * 256] = 0xF000; } } } |
The variable 'drawSub' is 'true'.
Later on, I find the relevant buffers and read parts in via
Code: |
u16* src = (u16*)bgGetGfxPtr(bg); u16* src2 = (u16*)bgGetGfxPtr(bg_sub); for(int i = R.x0;i < R.x1;i++){ for(int j = R.y0;j< R.y1;j++){ if(drawSub){ bool useSrc2 = j - drag.y >= SCREEN_HEIGHT; int dj = useSrc2 ? j - SCREEN_HEIGHT - drag.y: j - drag.y; dst[i + j * SCREEN_WIDTH] = (useSrc2 ? src2 : src) [i - drag.x + dj * SCREEN_WIDTH]; } else { dst[i+j*SCREEN_WIDTH] = ARGB16(1,31,0,0); } } } |
Where R is a 'box' where I want to reuse the screen to copy to a buffer. dst is an appropriately sized buffer. After a bit more rendering to dst, I throw all of dst onto the buffer with:
Code: |
int y, x; for(x = 0; x < SCREEN_WIDTH;x++){ for(y = 0; y < SCREEN_HEIGHT * 2;y++){ bool topScreen = y < SCREEN_HEIGHT; uint16* screen = topScreen ? main : sub; int dy = topScreen ? y : (y-SCREEN_HEIGHT); if(topScreen || drawSub){ screen[x + dy * SCREEN_WIDTH ] = image[x + y * SCREEN_WIDTH]; } } } |
Where image = dst; and 'main'/'sub' are found the same way I found 'src' and 'src2' up above.
Is this all correct? It looks like something is writing a datastructure to my VRAM, but surely this is disallowed in general right?
If you want to see this bug in action, grab the release build and open a pdf then scroll around. Source code is available on that same page if you want to look at it in more detail.
As always, Any help on this is appreciated!
Last edited by albinofrenchy on Sat Feb 14, 2009 2:32 pm; edited 1 time in total