Exception with ExitModalLoop

I create one task named thread2 using AsyncTaskExecuter from a function which is running in some thread as mentioned below.

 

func1()

{

create task thread2

// call RunModalLoop on alert window   //this blocks func1 till above thread2 completes


theDialog.setContentComponent (&theDialogPane, true, true);

theDialog.centreAroundComponent (NULL, theDialog.getWidth(), theDialog.getHeight());

theDialog.runModalLoop();
 

 

}

 

thread2func()

{

   if (no error) 

   {

      run task

   }

   call exitmodalstate on alertwindow to signal func1 about completion of thread2

}

 

Now here I have one issue, in case of some error, thread2func() reaches execution of line call exitmodalstate but func1() has not reached to line theDialog.runModalLoop();

 

So when calling exitmodalstate, it throws unhandled exception.

 

I also tried like this, but then it does not close dialog window and dialog keeps running


if(component.getParentComponent() != NULL)
 {
               component.getParentComponent()->exitModalState(10);

}

 

I get exception at below line   "if (flags.currentlyModalFlag)" in exitmodalstate function

 


void Component::exitModalState (const int returnValue)
{
    if (flags.currentlyModalFlag)
    {
 

}

 

How to handle this exception

It's not a C++ exception, it's a crash - you've probably got a null or dangling pointer.

Yes, I know that it is because of null pointer. But how to use RunModalLoop and ExitModalstate to create thread. I am getting exception becuase of execution difference in thread. i.e. ExitModalState is called in one thread before runModalLoop is called in other parent thread. Please provide me some sample code or link on how to create thread and abort thread progrmatically using RunModalLoop and ExitModalstate

The two things you need to know about runModalLoop are:

1. DO NOT USE IT! Modal loops are bad, dangerous, and impossible on some platforms. Asynchronous modality is fine with enterModalState/exitModalState, but avoid actually running a dispatch loop.

2. Do everything on the message thread. This stuff isn't thread-safe. None of the UI classes are.

(Just noticed that our docs for runModalLoop doesn't actually contain a warning about avoiding it - I'll fix that up)