writepixelfast problems

Blitz3D Forums/Blitz3D Beginners Area/writepixelfast problems

Steve Elliott(Posted 2004) [#1]
[CODE]

For particle.particles = Each particles ; draw particles

col = particle\red Shl 16 ; convert to pixel colour
col = col+particle\green Shl 8
col = col+particle\blue

LockBuffer
WritePixelFast(particle\x#,particle\y#,col)
UnlockBuffer

If particle\debris_size > 1
LockBuffer
WritePixelFast(particle\x#+1.0,particle\y#,col)
WritePixelFast(particle\x#,particle\y#+1.0,col)
WritePixelFast(particle\x#+1.0,particle\y#+1.0,col)
UnlockBuffer

If particle\debris_size > 2
LockBuffer
WritePixelFast(particle\x#+2.0,particle\y#,col)
WritePixelFast(particle\x#+2.0,particle\y#+1.0,col)
WritePixelFast(particle\x#,particle\y#+2.0,col)
WritePixelFast(particle\x#+1.0,particle\y#+2.0,col)
WritePixelFast(particle\x#+2.0,particle\y#+2.0,col)
UnlockBuffer
EndIf
EndIf

Next

[/CODE]

Why does this code crash? :(


eBusiness(Posted 2004) [#2]
You don't specify what buffers to lock and unlock, at least that's a problem.

[edit] Ooops, just checked the docs, that was ok, sorry.


Steve Elliott(Posted 2004) [#3]
Duh! Forgot to allow for the width of the particle - it was writing outside the screen boundary. It works now.


Yan(Posted 2004) [#4]
You only need to lock/unlock the buffer once, outside the loop.


YAN


Steve Elliott(Posted 2004) [#5]
Thanks Yan - I tried that before editing my code - which wasn't the problem anyway.


Yan(Posted 2004) [#6]
I know. Just a general tip. :o)


YAN