CustomBuf() problem

A PocketC native palm library offering native forms and assorted utilities

Postby Mikael on Thu Sep 15, 2005 8:13 am

Perhaps I'm misunderstanding the docs, but I'm trying to allocate memory for a 320x160 buffer for a background bmp of the same dimensions, the idea being to get the screen to scroll left or right once a sprite reaches the screen boundry.

I've tried a little test with the following:


for(i=0; i<100; i++){
CustomBuf(1,320,160);//create custom draw buffer
FastBmp(0,0,Guilin);//put background in buffer 1
FastBmp(xPos, yPos,Square);//sprite
CustomBuf(0,320,160);//create custom display buffer
CopyBuf(0,1);//copy background to buf 0
xPos=xPos+2;//move the sprite to the right

with varying results. I have my pilrc form set to 320x160 - not sure if it should be. If I attempt to run it on the simulator, I receive an alert saying, 'PToolboxLib.cpp, line 474, memory alloc failure.' and an alert on the Emulator saying, 'No form to return to.' when I exit. The strange thing is I don't get these alerts when I run the app with SetDrawBuf instead of CustomBuf. I've also tried reducing the bmp, form and custom buffers to 160x160 and get a strange blinking, on screen - again this doesn't happen when I substitute SetDrawBuf for CustomBuf.

Where am I going wrong?

Thanks in advance,


p.s. Is it even possible to get the screen to scroll, or would I have to stick to 160x160 and switch forms to display a new bmp?
Posts: 156
Joined: Sun Apr 13, 2003 9:19 am
Location: Denmark

Postby jstadolnik on Thu Sep 15, 2005 10:29 am

The problem likely is that the screen buffer (#0 is 160 by 160 pixels), as such when you do CopyBuf(0,1) things go haywire. The buffer sizes have to match when using CopyBuf()(they may even have to full screen sized, I don't recall off the top of my head). Use CopyRect() instead to deal with copying data from differently sized buffers.

PocketC has built-in buffer functions now too, if you don't need to do rotations or zooming (as can be done with CopyRect(), you might consider using them).


The PToolboxLib guy.
Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA

Postby Mikael on Thu Sep 15, 2005 11:07 am

Thanks Joe,

That did the trick!

Posts: 156
Joined: Sun Apr 13, 2003 9:19 am
Location: Denmark

Return to Pocket Toolbox

Who is online

Users browsing this forum: No registered users and 1 guest