Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global console variables are being defined more than once #36

Open
jamesu opened this issue Sep 26, 2012 · 2 comments
Open

Global console variables are being defined more than once #36

jamesu opened this issue Sep 26, 2012 · 2 comments
Labels

Comments

@jamesu
Copy link
Contributor

jamesu commented Sep 26, 2012

After modifying the console variable system I noticed that console variables were being added more than once in Con::init. If for example you put a breakpoint in "EditTSCtrl::consoleInit()", you'll notice its called at least 12 times. For "ShapeBase::consoleInit()", 8 times.

The issue seems to be when you don't override consoleInit in a derived class the ConcreteClassRep helper ends up calling the nearest implementation in a base class. Since ::consoleInit() is only usually used to define global variables, the extra calls are essentially redundant.

e.g.

// Calls MyConsoleObject::consoleInit during console init, great!
class MyConsoleObject : SimObject {
   static void consoleInit();
};

// Calls MyConsoleObject::consoleInit() during console init, ...
class MyDerivedConsoleObject : MyConsoleObject {
};

// Still calls MyConsoleObject::consoleInit() during console init, ...
class MyOtherConsoleObject : MyDerivedConsoleObject {
};

Possible solutions:

  1. Create an empty consoleInit function in the next derived class.

  2. Use a more flat class hierarchy.

  3. Expose consoleInit in some other way which prevents this duplication.

@camporter
Copy link
Contributor

Does this also mean that some calls to the parent consoleInit are also redundant? I've got a bit of code together to add missing consoleInit static methods to the relevant child classes, but I wasn't sure if this also should be cleaned up.

@crabmusket
Copy link
Contributor

Thanks for the catch. I think the simplest solution for now is to create stubs in derived classes and update the documentation in ConsoleObject to make this clear (IIRC, that class has documentation about deriving new subclasses).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants