PocketMatrix forums

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

Debugging question re: PHAL/Frog

I'm running through debugging why my game won't run now it's built for WM5. I have tested my Sprite function by adding it to the Blit sample & copying the same graphics across and they work fine there so there's no simple issue but when I draw a sprite in SPace Treker the blit fails on the line:-
Code:
Pixel* pDest = buffer.GetPixels( destRect.left, destRect.top );
which is in algo2d.h
The Sprite seems to have a correct surface. I can see the data in memory & it looks good as do the various variables for the sprite. At least 10 or so Blits have already happened successfully.

Any pointers to what may be happening are welcome.
Not that I really expect it to help me help you, but what is the nature of the failure your seeing? What exception are you getting?
First-chance exception at 0x0008efe0 in treker.exe: 0xC0000005: Access violation reading location 0x00000010.
First-chance exception at 0x0008efe0 in treker.exe: 0xC0000005: Access violation reading location 0x00000010.
Unhandled exception at 0x0008efe0 in treker.exe: 0xC0000005: Access violation reading location 0x00000010.
The thread 0xef91475e has exited with code 0 (0x0).
> treker.exe!PHAL::Surface::GetPixels(int x = 0, int y = 200) Line: 57, Byte Offsets: 0x24 C++
//< Retrieve a pointer to the pixels.

One possible could be that there's a temporary surface not getting created through 'lack of memory' though I believe that the amount of heap & stack is enough based on my settings as I have tried many.
I can now see that the sprite data is getting overwritten by something. If I reload the data just before I draw then the blit works.

Question is, what could be going wrong to cause my sprite data ( a surface) to be zapped, possibly during the blit operation. Has there been a subtle change in the way the SDK works?

I'm going to stick in a 'buffer' to try to protect my sprites as a test
Conan, are you alloc'ing memory for arrays? I've seen loads of strange problems from not calculating the right size - and overwriting the end of the array and anything else in the way.
The thing is that this game was completed a year ago and was 100% stable on PF .7 It was running on PF8 with HAL just as a test as well many months back so all I'm doing is re-building for WM5 on VS2005 beta. As I'm using the new imaging factory fixes I would have worried about that code however all the demos work and also my own sprite code works fine when dropped into the Blit demo. It seems to be that the surface holding the sprite image is fine until it's drawn one. I can even see where a sprite starts fine and then it's data is getting damaged in the same frame so something wierd is happening deep down. I checked the memory where the data is stored and before hitting the blit code it's all fine.
Are there any optimizations enabled now that weren't before? Especially since your building with VS2K5 now, that's one possibility... I've seen all manner of odd problems that only occur when this optimzation or that optimization is enabled, even in debug mode once or twice... it's worth your time to menually disable everything, don't trust the build type config! :)
Hi Frank, I have had the optimisations all off and all on to no effect. I'm also thinking there's something new happening with memory management and about 20 other exotic causes though it's likely to be my code as usual even though I did not knowingly change anything. Bottom line is that samples work, game doesn't and memory is overwritten. I'm going to have to re-discover the debugging skills I had when I was an assembly level programmer.
I figured you'd already checked the obvious :) Never hurts to be reminded though, just in case.

I haven't even done PPC coding in close to a year now (hoping to get back to completing my GUI engine so I can finally redo Electro), so I think I've been about as much help as I can be (which is to say, NONE! :) )
My sprites get loaded from resources. The code in Frog for loading resources does not create a surface, it does a LockResource on the resource data. Could this be something to do with the data getting overwritten? does the Resource accidentally get released after the first time it's drawn by Blit & if so could that be new following bugfixes? Just thinking aloud here.

ps: Frank, it was exactly one year (minus 2 days) when I started work on VS2005/Space Treker since I completed the game. Since then I have done some PF coding assisting another developer but otherwise this is me getting going on the next game. I reckon that if I don't know why this game is failing there's no point starting the next.

update: discovered that decompressimage has a logfile built in. The file's data all seems ok? all rows like this
Decompressing Image HRESULT 0
Returning surface... HRESULT 0
Decompressing Image HRESULT 0
Returning surface... HRESULT 0
no errors so my sprites do have a valid surface but still something is getting into their data????

Will change a couple over from JPG to bitmap to see what happens. No luck, making the first 4 jpg's into bitmaps changed nothing. Noticed that PF did not have browse information so having added that it should help.

in this line here from the entry to blittransformmask:-
Code:
void BlitTransformMask( PixelFunction& F, PHAL::Surface& buffer, const Rect& destRect, const unsigned transform[3][2], const PHAL::Surface& source, Pixel mask )
the source contains valid everything inc the pixel data but lower down the line:-
Code:
Pixel* dest = buffer.GetPixels( x1 >> 6, dy >> 6 );
the buffer has a bad pointer to the m_pixels
Wasn't there a small bug with clipping at some point? I remember putting the "trivial reject" somewhere, but it was probably the polygon stuff.

If what's being draw being clipped?
Either way, I'd check the destRect values.