Help passing pointers to data through events - shared_ptr vs weak_ptr

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Help passing pointers to data through events - shared_ptr vs weak_ptr

      In summary, I'm trying to pass data from an input device to the game logic.

      It is a large block of data, so I am trying to pass by a pointer; a shared_ptr to be exact. What I have works. Mostly. During runtime it chokes in the delegate function that receives the data. I get:

      Debug Assertion Failed!
      blah blah blah

      Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

      blah blah blah
      (Press Retry to debug the application)


      Here is what I have so far...

      Source Code

      1. //relevant Controller Code
      2. IHand *ihand = 0;
      3. QueryHandData(ihand)
      4. shared_ptr<IHand> ishared_hand;
      5. ishared_hand.reset(ihand);
      6. //send hand detected event with data to BaseGameLogic
      7. shared_ptr<EvtData_Hand_Controller> pHandEvent(GCC_NEW EvtData_Hand_Controller(ishared_hand, hand_event_trigger));
      8. IEventManager::Get()->VQueueEvent(pHandEvent);




      Source Code

      1. //relevant Event code
      2. class EvtData_Hand_Controller : public BaseEventData
      3. {
      4. shared_ptr<IHand> m_ihand;
      5. EvtData_Hand_Controller(shared_ptr<IHand> ihand, AlertData alertData) : m_alertData(alertData)
      6. {
      7. m_ihand = ihand;
      8. }
      9. shared_ptr<IHand> GetHandData(void) const
      10. {
      11. return m_ihand;
      12. }
      13. };
      Display All



      Source Code

      1. //Relevant code within Delegate function
      2. shared_ptr<EvtData_Hand_Controller> pCastEventData = static_pointer_cast<EvtData_Hand_Controller>(pEventData);
      3. shared_ptr<IHand> ihand = pCastEventData->GetHandData();
      4. //Handle hand data...


      Can you please tell me what I am doing wrong? Is there a better way to pass a pointer to data through the events?

      Thanks for your advice!
      -Troy

      The post was edited 7 times, last by jacktc ().