PocketMatrix forums

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

Bizarre Blit craziness

Dave Johnston · 07 Jul 2003, 21:35 UTC
Consider this:

Code:

Surface * src = 0;
if(state > 0)
src = m_pBubbleType->getPopped(abs(state) - 1, true);
else if(state < 0)
src = m_pBubbleType->getNormal(abs(state) - 1, true);
if(src != 0)
m_pRast->Blit(pos.x, pos.y, src);


When m_pRast blits this for the third time, it actually Blits nothing to m_pRast - at least, then blitting m_pRast's target surface to the display doesn't display anything.

HOWEVER, doing this:

Code:

Surface * src = 0;
if(state > 0)
src = m_pBubbleType->getPopped(abs(state) - 1, true);
else if(state < 0)
src = m_pBubbleType->getNormal(abs(state) - 1, true);

Display->CreateSurface(216, 64); // EXTRA LINE!

if(src != 0)
m_pRast->Blit(pos.x, pos.y, src);


Means it now works perfectly, but only when the additional CreateSurface call makes a surface similar to the dimensions shown.

This most probably isn't a bug in PF, but it's beat me, and none of my debugging is getting anywhere (takes me right into assembler). Anyone know what could cause this? I'm quite sure it's some pointer botching somewhere, but wondered if anyone else had a better understanding of why creating an unrelated surface before the blit would cause the blit to succeed.
Hi Dave, what's behind your functions? m_pBubble_type etc ? as it's them that are loading up src

Also is it just this extra line or any extra line?
(sometimes I think that there's a bug in if else so I always use the { } even when there's just one line but when I start thinking that way I know I'm wrong )
Dave Johnston · 08 Jul 2003, 06:47 UTC
Oops, yeah, should have said that src is a pointer to a Surface (and I've never had a problem with that area of functions - in debugging it returns a Surface - the right surface - perfectly fine).

It only works if I create a Surface, and also only on the actual device itself. The emulator is fine, and so is the desktop build. Only started occuring after I migrated 0.7.0 (again I stress - I'm quite sure it's not a PF bug).
Dave Johnston · 08 Jul 2003, 07:31 UTC
Ok, well I've now got it to draw correctly by not deleting the object of that class before I create a new one... (ie, instead of doing 'new, delete' on a pointer to an object with the code above, I'm just doing 'new'). But that's more of a workaround - the old object hasn't been deleted and is still in memory somewhere!! Primarily, deleting the old Surface seems to cause the error (from what I can see).

More specifically, when the destructor is called, I must not delete the Surface even if the pointer == 0!

Oh well, I'll keep battling on :)
Sounds like you have a memory (heap) corruption somewhere. These are unfortunately hard to find.
Dave Johnston · 08 Jul 2003, 17:48 UTC
Thierry wrote:
Sounds like you have a memory (heap) corruption somewhere. These are unfortunately hard to find.


Yep, that sounds about right! :roll:
Dave Johnston · 12 Jul 2003, 11:48 UTC
Uhh, anyone know anything about the 'datatype misalignment' error when running a program on an actual device?

I would investigate, but I'm suffering a few problems:
- my usb sync cable is broke
- my wifi network is broke
- on msvc++, it all runs fine
- the emulator restarts my computer (without xp even doing a mem dump)

I think I'm screwed. Any ideas?
Pejo Software - Per · 12 Jul 2003, 21:43 UTC
I also had the emulator reboot problem.
The solution for me was to install Windows CE .NET 4.1 (Platform Builder).
Dave Johnston wrote:
Uhh, anyone know anything about the 'datatype misalignment' error when running a program on an actual device?


First off, was this thread moved in here from PocketFrog or something?

Second, for ARM (and SH3 and MIPS AFAIK) simple types have to be aligned by their size (that's probably a gross simplification of the actual specification). However x86 does not have the restriction (although code will execute slower if it is not aligned).

For example, this should throw an exception (haven't tested it, but you should get the idea):

Code:

//buf is properly aligned (address is divisible by 4)
char buf[256];

//We can cast any part of buf to an int IF that
//address is divisible by 4, because sizeof(int)==4
int i;
for (i=0; i<sizeof(buf); i+=4)
(int)buf[i]=0;

//Now this is bad, because we are not properly aligned
for (i=1; i<sizeof(buf); i+=4)
(int)buf[i]=0;


So I'm assuming that the blit routine blits 32 bits at a time, thus the data needs to be 32 bit aligned.

Dan East
Dave Johnston · 13 Jul 2003, 08:27 UTC
Thanks Dan, that's a far better explanation than some of the things I found elsewhere on the web...

This thread was initially in the PF forum.
Dave Johnston · 13 Jul 2003, 12:56 UTC
Problem fixed.

Had some variables and unreferenced code in one of my classes - removing it (on the off-chance) seemed to fix the problem and also some apparently related side-effects.

If anyone's interested...
http://www.johnsto.co.uk/pocketpc/
Wow
nice gui! good music :-)
but that´s the only thing I can comment for now, when I try to play the game (any of the 2 modes ) I get a Fatal Application Error
"Exception: 0x80000002
Address: 000111d4"

btw, I have a Cassiopeia EM-500 ( mips )

i´m curious to play the game though, waiting for a fixed version
Dave Johnston · 14 Jul 2003, 06:54 UTC
HTK wrote:
Wow
nice gui! good music :-)
but that´s the only thing I can comment for now, when I try to play the game (any of the 2 modes ) I get a Fatal Application Error
"Exception: 0x80000002
Address: 000111d4"

btw, I have a Cassiopeia EM-500 ( mips )

i´m curious to play the game though, waiting for a fixed version


Argh! That's the problem of developing without a mips device to test on... Hmm, 0x80000002, that's the datatype misalignment error. ^%$#*!!!

I'll look into it. Thought I had it fixed. Grrr.