PocketMatrix forums

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

Intersect function causes exception

I have been using the intersect function of Gapidraw 1.0 for collision detection and I have run into the following problem: with certain surfaces using the Intersect function results in an unhandled exception in gapidraw.dll. I have checked all parameters I pass to the function and they all seem to be valid. I am using two color-keyed surfaces and a two rectangles (not the whole surface) for the intersect test. The error I get (in the debugger) is: First chance exception (GAPIDRAW.DLL): 0xC0000005: Access Violation. The last lines in the debug output window are:
Data Abort: Thread=8f7ae57c Proc=8c0d4470 'Demo.exe'
AKY=00200001 PC=009485e4 RA=00000000 BVA=000e70d8

Has anyone encountered this before?
Hi,

Very strange. Exception 5 is typically used when accessing uninitialized memory areas.

I tried changing the MaskDemo (which is shipped with GapiDraw) so that both surface use rectangles. No crash. I also looked through the source code for Intersect.

Please verify the parameter "POINT* pIntersection". This is a return value, and it must point to an initialized memory space. Using an uninitialized pointer here could easily cause GapiDraw to crash. Please report back again if all parameters are indeed correct, so I can have another look at it before I release the next GapiDraw tomorrow.

/Johan
Ok, I have checked all parameters and they really seem to be valid. Notice that the exception only occurs when there really is a collision between the two rectangles, if there is no collision, the function works fine. The POINT paramater is just a local variable, declared in the same function the Intersect function is called. The function looks like this:

Code:

bool CEsPpSprite::CheckCollision(CEsPpSprite* pCheckSprite)
{
bool bRetVal = false;
POINT intersectPoint;

#ifdef _DEBUG
TCHAR szDebugString[512];
swprintf(szDebugString, TEXT("sprite1 %d,%d srfc 0x%x rect (%d,%d)-(%d,%d) sprite2 %d,%d srfc 0x%x rect (%d,%d)-(%d,%d)\n"),m_worldX, m_worldY, m_framesSurface, m_FrameRects[0].left,m_FrameRects[0].top,m_FrameRects[0].right,m_FrameRects[0].bottom,pCheckSprite->m_worldX, pCheckSprite->m_worldY, pCheckSprite->m_framesSurface, pCheckSprite->m_FrameRects[0].left,pCheckSprite->m_FrameRects[0].top,pCheckSprite->m_FrameRects[0].right,pCheckSprite->m_FrameRects[0].bottom);
OutputDebugString(szDebugString);
#endif

if (m_framesSurface->Intersect(m_worldX, m_worldY, m_framesSurface, &m_FrameRects[0],
pCheckSprite->m_worldX, pCheckSprite->m_worldY, pCheckSprite->m_framesSurface, &pCheckSprite->m_FrameRects[0], &intersectPoint) == GD_OK)
{
if (!(intersectPoint.x==-1 && intersectPoint.y==-1))
bRetVal = true;
}

return bRetVal;
}

The last debug output looks like this:

sprite1 224,224 srfc 0xaba60 rect (0,0)-(32,32) sprite2 201,224 srfc 0xaceb0 rect (0,0)-(32,32)

If you like you can contact me during working hours by icq, you can send me an e-mail if you want my icq number.
This is now a confirmed issue and a fix is included in GapiDraw 1.01 (thanks to Jeroen for the feedback).

/Johan