vram32
Empty content…
Empty content…
Here are two ways:
main()
, you’ll never run into problems with memory safety unless you try to delete it, or try to store the pointer in a smart pointer (shared or unique, which will delete it when the ptr gets destroyed).GetSubsystem<MyApp>()
whenever you want it. I have been pondering if this is architecturally sound or basically flawed/dangerous OO. Note: executing RemoveSubsystem<MyApp>()
will crash your program.The correct way to do it (pardon my edits viewers) is to add this macro to your application class declaration:
class MyApp final : public Application
{
URHO3D_OBJECT(MyApp, Application);
...
}
Then in the constructor register as a subsystem:
MyApp::MyApp(Context *context) : Application{context}
{
context_->RegisterSubsystem(this);
}
Then use it as a standard subsystem:
GetSubsystem<MyApp>()->Test();
Note: in your example App::Test()
could be declared static, which would allow you to call it from anywhere without needing an instance of App
.
You could also do DynamicCast<App>(GetSubsystem<Application>())->Test()
.
Yeah it’s pretty verbose though. Adding the macro is super easy
Also, welcome to the forums!