Page MenuHomePhabricator

Tutorial steps crash
Closed, ResolvedPublic

Description

Due to missing initialization of focus manager. Mathias knows some details. @Daniel: can you try to find someone to fix this quickly during bug squashing tomorrow? It's probably a relevant bug for our guests. @Tobi,Ingmar: any ideas?

Event Timeline

Will have a look at it.
Should be no big problem.

Cite from Mathias S.: "Recently, at least some of the tutorial applications (tested Step3, Step6,
Step8) produce a crash in mitk::GlobalInteraction::AddFocusElement(). The
variable m_FocusManager has not been initialized properly. This seems to be
related to the recent chhanges applied to GlobalInteraction (r19557)."

Mathias, in Tutorial step 3, the GlobalInteraction is not used. Is it crashing at your system, too? Only step 6-8 use GlobalInteraction.

Found the reason: I just forgot to initialize GlobalInteraction here.
Since revision [SVN revision 19503], this is mandatory.
Will post the fix as soon as it compiled.

Also will add an Exception to the GetInstance() method when called if not initialized, then at least it should be clear where the error comes from.

Or Ingmar, would it make sense to call the default initializer when the singleton is first created in GetInstance()?

(In reply to comment #3)

Mathias, in Tutorial step 3, the GlobalInteraction is not used. Is it crashing
at your system, too? Only step 6-8 use GlobalInteraction.

Yes, step 3 also produces a crash. In line 122, QmitkRenderWindow is instantiated

QmitkRenderWindow renderWindow;

which in turn instantiates BaseRenderer, in which GlobalInteraction is accessed.

Thanks for looking into this!

Okay, this is a problem.
In MITK ExtApp etc., GlobalInteraction is created and initialized via a openChrry Activator. As the tutorial does not call this, GlobalInteraction is never initialized.

Sascha, would it make sense to create a seperate activator for the tutorial?
Or better initialize GlobalInteraction somewhere else, like in BaseRenderer, if it is not already initialized, with default values?

Using a bundle activator makes no sense for the tutorials, since they are not openCherry applications.

From my knowledge about singletons, shouldn't they be fully initialized when GetInstance() returns? Everything else would lead to too much trouble (as we can see...).

Well, this is actually the problem.
GlobalInteraction, and with it the FocusManager, StateMachineFactory and EventMapper, as members, have been changed to be initialized by an Activator for the MITk main application. But, in the Tutorial, RenderingManager->GetInstance is called without initializing the GlobalInteraction. This creates an instance of BaseRenderer, which then needs GlobalInteraction.

A possible (not very nice) solution would be to create and initialize a default instance of GlobalInteraction in each tutorial step. This is done for the tests by now.

Do you have an idea for a better solution?

Your last suggestion sounds like a good intermediate solution to me.

Ultimately, one should (must) call GlobalInteraction::Initialize("") in GlobalInteraction::GlobalInteraction() and remove the if(this->IsInitialized()) check in the Initialize method (surely, one must check for side-effects).

Probably, the Initialize method should be renamed to something like "SetInteraction". We already had a similar discussion in the MITK meetings about GlobalInteraction to be more flexible.

The problem here is that the behaviour of GlobalInteraction->Initialize is different for an application built from source code (which has StateMachine.xml as file found at mitk::StandardFileLocations()) and an Installer (which has the XML content compiled in as Qt resource). GlobalInteraction->Initialize respects both cases, but not the tutorial, which has none of both, as it seems.

Yes, but wouldn't that be application specific anyway? The call to Initialize in the GlobalInteraction constructor should initialize the object with reasonable defaults. Why is the call to m_StateMachineFactory->LoadStandardBehavior() not working for the tutorials?

Because GlobalInteraction is then initialized via BaseRenderer, which should not be the "normal" behaviour, because it should be initialized before. It is not initialized anymore in the GlobalInteraction constructor. Initialize() is to be mandatory called seperately.

In the moment, GlobalInteraction is supposed to be available and intitialized before any application can be available.

Maybe we can find a suitable solution tomorrow.

Should bge fixed now, as in Rev. [SVN revision 19736]
GlobalInteraction is now initialized in QmitkRegisterClasses() function if it is not already. For the main application, this function is called, too, in the CommonActivator, but GlobalInteraction is initialized earlier.