PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Sorry for the long post but i'm a total newbie at this

BasicBubble · 14 Feb 2003, 23:52 UTC
I've been coding in C for quite a while now and when the opatunity arose to program games for my pocketpc i jumped at the chance to get embedded Visual C++ and pocketfrog.
My problem is that I have only coded in TurboC++ 3 which doesnt seem to be helping me learn visual C++
My first attempt at coding was to modify the plasma sample provided to make it run like a fire program i wrote using the 13h graphics mode in turboC++

Code:
//////////////////////////////////////////////////////////////////////////////
//
// Helpers
//
//////////////////////////////////////////////////////////////////////////////

namespace
{
double hyp( double a, double b )
{
return sqrt( a*a + b*b );
}

void Smooth (byte *buffer1)
{
byte* fire2 = (byte*) malloc(FIRE_WIDTH * FIRE_HEIGHT * sizeof(byte));
int x,y,c;
memcpy (fire2, buffer1, 76800);
for (x=0; x<230; x++) for (y=0; y<318; y++)
{
c = (y << 8)+ (y<<6) + x;
buffer1[((y-1) * 240)+x] = (fire2[c-241] + fire2[c-240] + fire2[c-239]
+ fire2[c-1] + 0 + fire2[c+1]
+ fire2[c+239] + fire2[c+240] + fire2[c+241]) >> 3;
free(fire2);
}

}

}



//////////////////////////////////////////////////////////////////////////////
//
// Plasma
//
//////////////////////////////////////////////////////////////////////////////

Plasma::Plasma()
{
m_config.szWindowName = _T("Fire Sample");
m_config.orientation = ORIENTATION_NORTH;
m_config.splashScreenTime = 1;
}



bool Plasma::GameInit()
{

fire = (byte*) malloc(FIRE_WIDTH * FIRE_HEIGHT * sizeof(byte));
srand( PocketPC::GetTickCount() );
return true;
}



void Plasma::GameLoop()
{
DisplayDevice* display = GetDisplay();

Surface::LockInfo buffer;
display->GetBackBuffer()->Lock( buffer );
int width = display->GetWidth();
int height = display->GetHeight();
int z;

for( int x = 0; x < 100; ++x )
{
z = rand() % 240;
fire[315 * 240 + z] = 254;
}

Smooth(fire);

for (x=0; x<240; x++)
for (int y=0; y<320; y++)
buffer.pixels[y*240 +x]=Color(fire[y*240 +x],0,0);

display->GetBackBuffer()->Unlock();

display->Update();
}



void Plasma::GameEnd()
{
free(fire);
}

That is my first attempt, it compiles, but causes an illegal operation when run, can any body give me any help as to where i'm going wrong, please post all mistakes as i really want to learn how to code for pocketpc, thanks alot
BasicBubble
You make free(fire2) inside for(...) in Smooth(...) procedure. :wink:

p.s. since you use free calls use new instead of malloc.
What? malloc() goes with free()... new goes with delete...
Surely, yes. I was stumbled... :oops: