Jump to content
  • Advertisement
Sign in to follow this  

Having Problems with "The Tower" from Programming Role Playing Games with DirectX 2Ed

This topic is 4391 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I tried running this game to get a feel for what the end result of the book would be and I've come across a very frustrating (for me anyway) bug. Everytime I try to start a new game, or quit the game, I get an unhandled exception at 0x7c901230. Since it didn't have the source code readily available from the executable. I decided to put all the info into a project and compile it from there in order to see where the problem is coming from. So I run it in Debug mode and come up to this function
BOOL cVertexBuffer::Unlock()
{ 
  if(m_pVB == NULL)
    return FALSE;


if(FAILED(m_pVB->Unlock()))
    return FALSE;

  m_Locked = FALSE;

  return TRUE;
}
where the bold line is the culprit for this error (or at least where the code breaks) My question is, has anyone come across this problem before? And barring that fact, Can anyone help me fix it? I have the most recent DirectX version and my video card drivers are all up to date.

Share this post


Link to post
Share on other sites
Advertisement
1) your m_pVB object may have been released before you call Unlock().
2) your m_pVB object may not point to the correct object

You should try to find where you release your object, and when you unlock it.

Regards,

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
1) your m_pVB object may have been released before you call Unlock().
2) your m_pVB object may not point to the correct object

You should try to find where you release your object, and when you unlock it.

Regards,


Looking in at the code, it's calling unlock during a call to MenuTexture.Free(). Which is handled during the cApp::MenuFrame(...)

It appears to be pointing to the correct type of object (IDirect3DResource9)

The call stack looks like this

Game.exe!cVertexBuffer::Unlock() Line 2941 C++
Game.exe!cVertexBuffer::Free() Line 2877 C++
Game.exe!cApp::MenuFrame(void * Ptr=0x000edc58, long Purpose=2) Line 806 C++
Game.exe!cStateManager::Pop(void * DataPtr=0x000edc58) Line 218 + 0xf C++
Game.exe!cApp::MenuFrame(void * Ptr=0x000edc58, long Purpose=3) Line 843 C++
Game.exe!cStateManager::Process(void * DataPtr=0x000edc58) Line 243 + 0xf C++
Game.exe!cApp::Frame() Line 244 C++
Game.exe!cApplication::Run() Line 93 + 0xd C++
Game.exe!WinMain(HINSTANCE__ * hInst=0x00400000, HINSTANCE__ * hPrev=0x00000000, char * szCmdLine=0x00141f20, int nCmdShow=1) Line 628 + 0xb C++
Game.exe!WinMainCRTStartup() Line 251 + 0x30 C
kernel32.dll!7c816d4f()
kernel32.dll!7c8399f3()

Where Free() calls Unlock.
MenuFrame creates and frees the VertexBuffer (among other things)

Going backwards through it, I'm not finding where the m_pVB variable would have been lost incorrectly.

Could the problem be that the m_pVB was not created correctly?

Share this post


Link to post
Share on other sites
Ok, I've found what appears the be the culprit.

The cVertexBuffer::Set Function.

The code logic seems to follow this path

When initializing the menu, it creates a VertexBuffer then sets the Vertices (followed by loading of texture, selection menu, Font and Camera setup)

Which looks to run fine.

Then when you chose an option on the screen (in this case New Game, though Quit and I'd assume Load game would give the same error), It prepares to shutdown the Main Menu (which makes sense). In doing so it goes to Free the Vertex Buffer.

Now the problem appears to be that when you Set the vertexBuffer in the initialization step. You've already freed the Vertex buffer, because this is what the set fuction does.


BOOL cVertexBuffer::Set(unsigned long FirstVertex, unsigned long NumVertices, void *VertexList)
{
if(m_Graphics == NULL || VertexList == NULL || m_pVB == NULL)
return FALSE;
if(m_Graphics->GetDeviceCOM() == NULL)
return FALSE;

// Lock the vertex buffer
if(Lock(FirstVertex, NumVertices) == FALSE)
return FALSE;

// Copy vertices to vertex buffer
memcpy(m_Ptr, VertexList, NumVertices * m_VertexSize);

// Unlock vertex buffer
if(Unlock() == FALSE)
return FALSE;


return TRUE;
}


So inherent in the Set function is a call to lock and then unlock the VB. So when Unlock() is called later in the shutdown phase of the Main Menu it crashes.

So at least I know now what the problem is. I just need to figure out how to fix it. Though if anybody has any thoughts on it I'd appreciate the help.

Share this post


Link to post
Share on other sites
I am also using this book and I get numerous errors trying to compile the source in most of the chapters. (Most notibly the game core)
I wouldn't recomend it to anyone who can't rework the code..... Just sayin' your not the only one.

Share this post


Link to post
Share on other sites
ok that's fixed.

Now I have a new problem (sigh).

The CheckIntersect function isn't working and crashing with another access violation.

It's probably something similar. But it's still very frustrating.

Share this post


Link to post
Share on other sites
Quote:
Original post by Plasmarobo
I am also using this book and I get numerous errors trying to compile the source in most of the chapters. (Most notibly the game core)
I wouldn't recomend it to anyone who can't rework the code..... Just sayin' your not the only one.

That's good (yet at the same time bad) to know.

Though should there be an addendum to this book if the code has that many errors?

Share this post


Link to post
Share on other sites
Quote:
Original post by kontrol
Quote:
Original post by Plasmarobo
I am also using this book and I get numerous errors trying to compile the source in most of the chapters. (Most notibly the game core)
I wouldn't recomend it to anyone who can't rework the code..... Just sayin' your not the only one.

That's good (yet at the same time bad) to know.

Though should there be an addendum to this book if the code has that many errors?


I remember I saw a fairly recent code update on the book's web site (see page 814 for the URL). Maybe it correct your own problems.

Regards,

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
His website is only about the 1st edition, there is nothing about the 2nd edition.
Or do you have another url than http://home.att.net/~rpgbook/ on page 814?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!