Page 1 of 1

Padding bytes in 2DDrawing Buffer

Posted: Wed Apr 18, 2012 2:52 am
by kenmo
When writing directly to a screen's drawing buffer, I know that each horizontal line may have extra non-visible "padding" bytes after the end - that is what DrawingBufferPitch() is useful for.

But should I avoid writing into these padding bytes? Or is it perfectly safe?

For a very simple example, would this be a safe (although strange) way to clear a screen?

Code: Select all

; example:
; ScreenWidth  = 640
; ScreenHeight = 480
; ScreenDepth  =   4 (bytes)

If StartDrawing(ScreenOutput())
  FillMemory(DrawingBuffer(), DrawingBufferPitch() * ScreenHeight, Color, #PB_Long)
EndIf
I ask because I've had some IMA crashes around code which directly writes to the buffer. As far as I can tell, I am correctly writing to either the visible bytes or the padding bytes, nowhere else...

Re: Padding bytes in 2DDrawing Buffer

Posted: Wed Apr 18, 2012 5:39 am
by Thorium
It is save. Are you sure you set the depth correctly? Thr number normaly represents the depth in bits not in bytes.

Re: Padding bytes in 2DDrawing Buffer

Posted: Thu Apr 19, 2012 5:00 am
by kenmo
Yes the depth is usually referred to as 32-bit, but I used a depth-in-bytes variable (typically = 4 or 2) for calculating memory block sizes... but I didn't really need to include that in my first post above.

I will keep investigating, and post again if I can reproduce the crashes or if I find it is my own bug.