Game Development Community

NetEvent Problem?

by Matthew Rudge · in Torque Game Engine · 02/22/2007 (6:59 pm) · 4 replies

I've been recently looking at the NetConnection::eventReadPacket() method, and I've encountered a problem with NetEvents. The NetEvent I'm using is guaranteed but not guaranteed ordered. After it is created through ConsoleObject's static method create(), it is then unpacked and enters the

if(unguaranteedPhase)
{
...
}

section, where the NetEvent is processed and then has it's reference count decremented. Decrementing the reference count sets the object for deletion once it reaches zero and only zero. At this point, the loop either continues and the NetEvent pointer becomes invalid or the function exits if there is an error.

My question concerns the reference count. At no point in this method is the reference count incremented between the NetEvent creation and the NetEvent::decRef() call. Therefore, by the time the reference is decremented, the reference count of the object goes to -1 and is not deleted (since the decRef checks only against zero and not below zero). Is there another place that the NetEvent is possibly being deleted? Or is this a memory leak?

My particular problem arises when I increment the NetEvent reference count because I am adding it to a queue when the NetEvent is processed. When the queue is processed, the NetEvent pointer points to bad memory (deleted) due to the decRef() call after the process.

Thanks for your thoughts and help!
~Matt

About the author

Recent Threads

  • Trimming TGE
  • Trimming TGE

  • #1
    02/23/2007 (8:50 am)
    Hmm...I've not seen this one before. Sending it to the teams to see if anyone has any thoughts.

    Which engine and version are you currently using?
    #2
    02/23/2007 (10:01 am)
    Hi Stephen!

    Thanks for the quick reply! It's good to hear from you...I'm using TGE version 1.5.

    I'm guessing that after the NetEvent is created, there needs to be a call to incRef(). In any case, to quickly find it in netEvent.cc:

    1) The creation of the NetEvent is line 279
    2) The "if" statement and decRef() starts at line 304

    Thanks for your help :)
    ~Matt
    #3
    02/23/2007 (4:49 pm)
    Thanks for the report, issue #2737. You probably need to add a incRef() in there. :)