PocketMatrix forums

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

PocketFrog 0.7 memory problems

Hi! I'm still using PF 0.7 and encountered a strnge behavor last night.

During initialization i created custom surface:
Code:

drawpic= m_pDD->CreateSurface(110,130);
drawpic->SetColorMask(Color(0,0,0));


After that i fill it with stupid looking rectangles :)
Code:


void DrawLevel(int l)
{
m_pDD->SetRenderTarget(drawpic);
std::vector<_level>::iterator Lev_It=m_pState->Levels.begin()+l;
for(int x=0;x<11;x++)
for(int y=0;y<13;y++)
{
switch((*Lev_It).map[x][y])
{
case 1:
m_pDD->DrawRect(x*10,y*10,x*10+10,y*10+10,Color(0,0,0));
m_pDD->FillRect(x*10+1,y*10+1,x*10+9,y*10+9,Color(255,0,0));
break;
case 2:
m_pDD->DrawRect(x*10,y*10,x*10+10,y*10+10,Color(0,0,0));
m_pDD->FillRect(x*10+1,y*10+1,x*10+9,y*10+9,Color(0,255,0));
break;
case 3:
m_pDD->DrawRect(x*10,y*10,x*10+10,y*10+10,Color(0,0,0));
m_pDD->FillRect(x*10+1,y*10+1,x*10+9,y*10+9,Color(0,0,255));
break;
case 4:
m_pDD->DrawRect(x*10,y*10,x*10+10,y*10+10,Color(0,0,0));
m_pDD->FillRect(x*10+1,y*10+1,x*10+9,y*10+9,Color(255,255,0));
break;
default:
m_pDD->DrawRect(x*10,y*10,x*10+10,y*10+10,Color(0,0,0));
m_pDD->FillRect(x*10+1,y*10+1,x*10+9,y*10+9,Color(128,128,128));
break;
};
}
m_pDD->Update();
m_pDD->SetRenderTarget(0);
};


And, after DrawLevel() any attempt to call LoadImage() results in out of memory error in release and
HEAP[GalaxyGate.exe]: HEAP: Free Heap block e4d4e8 modified at e4d4f8 after it was freed message in debug. What's wrong?
The code doesn't look that odd, except for the part where you call m_pDD->Update() and then set the rendertarget back to the backbuffer... You might want to swap those lines, or do another GetDisplay() after the Update(). (If you were using PF0.8.0, you'd have to call GetDisplay() after each Update() anyway.)

I'm pretty sure your problem is because of those two lines. You might try:
Code:

m_pDD->SetRenderTarget(0);
m_pDD->Blit(0,0,drawpic);
m_pDD->Update();

This assumes you want the drawn picture displayed to the screen.
no, that didn't help :(

It still causes "Unhandled exception at 0x77f75a58 in GalaxyGate.exe: User breakpoint." in debug and out of memory in release. I dug out my old code snipets an they are almost the same code and running without any problems :(
i localized the bug
it occured only when i call DrawLevel() from Game::Init()

i changed code and now everything works. Still i don't understand why it happened...