Problem with memcopy

BlitzMax Forums/BlitzMax Programming/Problem with memcopy

Why doesn't Blitz compile this piece of my program, complaining on the memcopy line with the following error?:::

Compiling:BounceTestGravity.bmx
Compile Error:Unable to convert from 'Int' to 'Byte Ptr'
[/Applications/BlitzMaxSetup100/PaulsTests1/BounceTestGravity.bmx;103;5]
Build Error: failed to compile /Applications/BlitzMaxSetup100/PaulsTests1/BounceTestGravity.bmx

psource is defined with Local psource:Byte Ptr initialized with PixmapPixelPtr(img,0,0) which is a pixmap. psize is an integer size in bytes:

	txtrp:TPixmap=LockImage(txtri,0,True,True)
	Local pdest:Byte Ptr
	pdest=PixmapPixelPtr(txtrp,0,0)
	MemCopy(pdest,psource,psize)        ' problem with this!
	UnlockImage(txtri)
	DrawImage txtri,objpos[o,0],objpos[o,1]

I'm trying to do a direct memory copy from the pixel data of a regular pixmap (in memory) to the pixel data of a locked image's pixmap in video ram. If I change the memcopy to a nested for-next loop for x and y, using writepixel and readpixel, it works, but what's wrong with the memcopy line?

Update ... I've found that the main problem in the entire program was using Global to define the psize variable.

Global psize:int=wid*hig*4

causes the later call to MemCopy to bomb out. None of the code is inside functions or similar, so in general the psize variable doesn't need to be global.

So I changed it to

psize:int=wid*hig*4

and it compiled and everything worked.

Of course that is after 10 million attemps to write alternative copying routines.

So... -why- didn't it like it being a Global?

That I don't know. This is a pretty simple program, there are no functions so basically all the variables should be accessible to all the program. I used some Local variables for speed but those are fine, so maybe it's a bug? Setting some of the variables to global and accessing them from within the same context (ie not within a function) seems to turn the variable into 0 instead of holding the correct value.