Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: CTVPhysics second instantiation and/or singelton usage  (Read 534 times)
AriusEso
Customers
Community Member
*****
Posts: 611

Esoteric


« on: January 06, 2009, 08:37:32 PM »

Hey,

Ok, I have an instance of CTVPhysics in one class. I finish using that class, clean it out etc etc. Then I instantiate a new class, a new instance of CTVPhysics and every function in the class works fine apart from SimulateFixedStep and Simulate. The debugger has given me two errors:

Error one:

Code:
iPhysicsIndex CXX0030: Error: expression cannot be evaluated

Error two completely screws everything, it's easier just to screen the debug( click for larger ):



Now, if you look you'll see I call the SetSolverModel function right before the SimulateFixedStep function. I did this to demonstrate that the issue is not scope. I can call any function from m_Physics apart from Simulate or SimulateFixedStep. I have also tried not releasing the first class and praying to the gods of singleton, but all hell still breaks loose. Either way I also get the debug message - "01-07-2009 01:28:43 | PHYSICS MANAGER : Already initialized !", when it simply isn't, I released it already.

Any ideas?
Logged

AriusEso
Customers
Community Member
*****
Posts: 611

Esoteric


« Reply #1 on: January 06, 2009, 09:01:09 PM »

Aha, hmm, after whining some more on IRC Aion pointed out that there is an "unload" function Smiley. That did the trick. Although, I do find it strange that destroying the class doesn't work just as well.  Grin
Logged

ZaPPZion
Community Member
*
Posts: 410


« Reply #2 on: January 07, 2009, 03:54:38 AM »

Destroying the class will probably not clean a couple static (internal) members (singleton stuff). That's why you'll need to unload it as well. So probably the instance of the Newton physics engine is a static member of the TVPhysics class. That means it doesn't get destroyed when you destroy an instance of the TVPhysics class.
I think that the way TV is using singleton design is cool, but it's not really singleton. I've tryed to create the same sort of behavior in a selfmade class, and came to the conclusion that it's not really singleton stuff, since you can instantiate the class. In singleton design, that's prohibited. So it's basicly a class with a couple static members with accessors, so it can use it internally without passing the tvphysicsengine reference to each other class.
Logged

Check out my website: www.bartkuipers.com
AriusEso
Customers
Community Member
*****
Posts: 611

Esoteric


« Reply #3 on: January 07, 2009, 09:57:10 AM »

Destroying the class will probably not clean a couple static (internal) members (singleton stuff). That's why you'll need to unload it as well. So probably the instance of the Newton physics engine is a static member of the TVPhysics class. That means it doesn't get destroyed when you destroy an instance of the TVPhysics class.
I think that the way TV is using singleton design is cool, but it's not really singleton. I've tryed to create the same sort of behavior in a selfmade class, and came to the conclusion that it's not really singleton stuff, since you can instantiate the class. In singleton design, that's prohibited. So it's basicly a class with a couple static members with accessors, so it can use it internally without passing the tvphysicsengine reference to each other class.

That doesn't explain why I could use every function but the simulate ones. I still find that odd. Either the reference is good or it isn't.

As for the singleton design pattern, surely you can reinstantiate - it simply passes itself back if it already exists. As example:

Code:
class MySingleton
  {
  public:
      static MySingleton* Instance();
  protected:
      MySingleton();
      MySingleton(const MySingleton&);
      MySingleton& operator = (const MySingleton&);
  private:
      static MySingleton* pinstance;
  };

//---

  MySingleton* Singleton::pinstance = 0;
  MySingleton* Singleton::Instance ()
  {
    if (pinstance == 0)
    { 
      pinstance = new MySingleton;
    }
    return pinstance;
  }

  MySingleton::Singleton()
  {
    //...
  }

Something like that.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks