Author Topic: Breakpoint triggered in VS 2005  (Read 37505 times)

AshMcConnell

  • Full Member
  • ***
  • Posts: 169
  • Karma: 3
    • View Profile
    • Sirocco Racing Simulator
Breakpoint triggered in VS 2005
« on: January 04, 2006, 06:08:45 AM »
Hi Follks,

I get the following error while debugging in the VS 2005 environment.  Does anyone know what might be causing it?  It seems to happen when I disconnect, or try to reconnect to a server in the same session.  I can continue and everything seems to work fine, but i'd like to know the cause.

Thanks for your help!
All the best,
Ash

Quote
"Windows has triggered a breakpoint in Sirocco.exe.

This may be due to a corruption of the heap, and indicates a bug in Sirocco.exe or any of the DLLs it has loaded.

The output window may have more diagnostic information"

In the output: -

"HEAP[Sirocco.exe]: Invalid Address specified to RtlFreeHeap( 099A0000, 099AFBAC )"




AshMcConnell

  • Full Member
  • ***
  • Posts: 169
  • Karma: 3
    • View Profile
    • Sirocco Racing Simulator
Re: Breakpoint triggered in VS 2005
« Reply #1 on: January 04, 2006, 06:14:53 AM »
Sorry, I should mention that this is with version 2417, also it seemed to work ok with VS 2003 (at least previous versions of Raknet did).

All the best,
Ash

pinniped

  • Full Member
  • ***
  • Posts: 133
  • Karma: -1
    • View Profile
Re: Breakpoint triggered in VS 2005
« Reply #2 on: January 04, 2006, 07:56:10 AM »
Well RakNet doesn't directly invoke that function so I can't imagine this being a RakNet problem.  Run your program in a debugger and get a stack trace.

AshMcConnell

  • Full Member
  • ***
  • Posts: 169
  • Karma: 3
    • View Profile
    • Sirocco Racing Simulator
Re: Breakpoint triggered in VS 2005
« Reply #3 on: January 04, 2006, 10:52:06 AM »
Hi Pinniped,

It's happening here: -

RakPeer::Disconnect()  Line 649   

When it is closing the socket.

Any ideas why this would happen?
All the best,
Ash

pinniped

  • Full Member
  • ***
  • Posts: 133
  • Karma: -1
    • View Profile
Re: Breakpoint triggered in VS 2005
« Reply #4 on: January 04, 2006, 07:06:22 PM »
Did you use the correct 'threading model' in your program?  The only other common bug I can think of is that someone did something like:

int *blah = new int;
delete [] blah;

The compiler won't spot such a problem but will segfault when run, so look carefully at memory deallocation stuff in 'Disconnect'.

I won't be able to look at the code for another week yet.  Are you using the cvs version?

Rak'kar

  • Administrator
  • Hero Member
  • *****
  • Posts: 6895
  • Karma: 291
    • View Profile
    • RakNet
Re: Breakpoint triggered in VS 2005
« Reply #5 on: January 05, 2006, 12:24:58 AM »
Hi Ashley, nice to see you back after so long.

A lot of data is deallocated in that function so it would be useful if you traced through and found out which line was causing it.  The most likely scenario is the system is out of memory for an allocation, possibly due to the size parameter in a send call being too large.

AshMcConnell

  • Full Member
  • ***
  • Posts: 169
  • Karma: 3
    • View Profile
    • Sirocco Racing Simulator
Re: Breakpoint triggered in VS 2005
« Reply #6 on: January 05, 2006, 10:09:25 AM »
Hi Kevin,

It has been quite a while, I have been trying to put a proper design into my game and network stuff has got pushed to one side for a while :).

Maybe the problem is that i'm just using the lib (included in the zip file) with the include files rather than including all the source in my project?  When I debug it only shows me the source of the Rakpeer .cpp

i.e.
Quote
if ( connectionSocket != INVALID_SOCKET )
   {
      closesocket( connectionSocket );
      connectionSocket = INVALID_SOCKET;
   }

it is actually saying that the "connectionSocket = INVALID_SOCKET;" line is causing the problem.  This is fairly unlikely i'd guess, so the source is probably slightly different than what is in the lib?

It is always this line that is reported, whether i'm using the server (on Initialization when there are connected clients disconnect is called) or the client when disconnect is called.

I may have missed something when updating between versions of Raknet as I haven't been paying close attention lately.

Thanks for your help
All the best,
Ash

Rak'kar

  • Administrator
  • Hero Member
  • *****
  • Posts: 6895
  • Karma: 291
    • View Profile
    • RakNet
Re: Breakpoint triggered in VS 2005
« Reply #7 on: January 12, 2006, 12:15:54 AM »
Please rebuild the lib with the lib static project.  You should then get a more accurate trace and can post that here.

ville

  • Not-a-newbie
  • *
  • Posts: 30
  • Karma: 0
    • View Profile
Re: Breakpoint triggered in VS 2005
« Reply #8 on: January 14, 2006, 08:09:54 AM »
I have always had this problem, from when I started using RakNet with VC6 last year, up to now with VS 2005. I've never actually found out what could be causing it, but I'm happy to hear someone else having similar problems. Haven't tried 2003 version, so I have no idea if that's the cure.

Here's a call stack, the > line is the last line I can trace to.

        ----
        ----
        ws2_32.dll!71ab9680()    
>     CormoonDebug.exe!RakPeer::Disconnect(unsigned int blockDuration=100)  Line 649   C++
        CormoonDebug.exe!RakServer::Disconnect(unsigned int blockDuration=100)  Line 102   C++
        CormoonDebug.exe!Server::~Server()  Line 93 + 0x19 bytes   C++ (This is my own server class)
        ----
        ----

Could it be the specific ws2_32.dll implementation on our machines? I guess mine is the one that comes with XP. Or is the closesocket being used wrong in RakPeer.cpp somehow?

Rak'kar

  • Administrator
  • Hero Member
  • *****
  • Posts: 6895
  • Karma: 291
    • View Profile
    • RakNet
Re: Breakpoint triggered in VS 2005
« Reply #9 on: January 16, 2006, 11:36:09 PM »
Are you using the multithreaded version of the run time libraries?

ville

  • Not-a-newbie
  • *
  • Posts: 30
  • Karma: 0
    • View Profile
Re: Breakpoint triggered in VS 2005
« Reply #10 on: January 17, 2006, 02:02:10 AM »
Aye, that I am.
I'm using Raknet as a static library. I tried using it by including the whole source, with the same result.

Rak'kar

  • Administrator
  • Hero Member
  • *****
  • Posts: 6895
  • Karma: 291
    • View Profile
    • RakNet
Re: Breakpoint triggered in VS 2005
« Reply #11 on: January 17, 2006, 02:29:42 AM »
I don't have the same code as you, so I want to confirm that you are crashing in the closesocket call?  I've never heard of that.  Does it happen every time, so if you just call Init and then Disconnect it will crash?

ville

  • Not-a-newbie
  • *
  • Posts: 30
  • Karma: 0
    • View Profile
Re: Breakpoint triggered in VS 2005
« Reply #12 on: January 17, 2006, 03:15:31 AM »
As Ashley said, it's crashing right here:

   if ( connectionSocket != INVALID_SOCKET )
   {
      closesocket( connectionSocket );<<<<this causes a breakpoint to be triggered
      connectionSocket = INVALID_SOCKET;
   }

And that's RakPeer.cpp line 649 or something in the newest downloadable version. And as Ashley said, it works alright after that if I just tell it to continue.

The example programs do the same for me as well, so I've been led to believe it's got something to do with either the compiler or my system. I'll try to do a Init & Disconnect when I get home. I might try to fiddle with the sockets as well to see if that's really the problem.

pinniped

  • Full Member
  • ***
  • Posts: 133
  • Karma: -1
    • View Profile
Re: Breakpoint triggered in VS 2005
« Reply #13 on: January 17, 2006, 05:37:35 AM »
Hmm... sounds like a classic race condition  -  deallocation may have occurred elsewhere but the contents had not yet been set to INVALID_SOCKET.

On the other hand, unlike a typical race condition you say that this happens consistently.  (However it is entirely possible to have a biased race so that the problem always triggers.)

Do you invoke RakNet functions from multiple threads or only from a single thread?  RakNet is not thread-safe - it has its own processing thread and sync schemes to deal with it, but if you invoke function calls from multiple points there is no telling what will happen.

ville

  • Not-a-newbie
  • *
  • Posts: 30
  • Karma: 0
    • View Profile
Re: Breakpoint triggered in VS 2005
« Reply #14 on: January 17, 2006, 06:14:20 AM »
Sounds like a race condition doesn't it. I tested it with just the following code in my WinMain.

Quote
RakServerInterface *rakServer;
rakServer=RakNetworkFactory::GetRakServerInterface();
rakServer->Start(32,0,1000,20000);
Sleep(1000);
rakServer->Disconnect(100);<<<< and this is where windows triggers a breakpoint
RakNetworkFactory::DestroyRakServerInterface(rakServer);

So it's not a problem with the threads in my program at least. I tried to see if Raknet called closesocket anywhere else before the one that crashes it, but I couldn't find find anywhere it did that.

One idea would be to check the return value of closesocket, but of course it will give none since it's crashing.