I'm not sure the status bar is deleted when removed from the main window, maybe 
its deletion is postponed to the next run loop cycle. The main problem is that 
the interactive prompt has still the status bar as its parent so it will get 
deleted when you do not expect. 
Qt memory management is quite tricky, especially in TeXmacs where we are forced 
to a pattern of usage of the framework which is not the one commonly adopted in 
writing Qt programs. I've often found myself redefining some classes just to be 
able to override the destructor and understand where exactly the object have 
been freed. Sometimes it is also useful to look into the Qt sources to check 
some behavior. They are more reliable and clear than the docs.....

max

On 7 nov. 2010, at 00:18, Miguel de Benito Delgado wrote:

> Hmm... I did step 4 in order to have the status bar deleted and that's why I 
> was removing myself (the QTMInteractivePrompt) from it before doing that, 
> because otherwise it would have blown. But then, what you say makes sense and 
> is perfectly consistent with my so-called fix preventing the crash, but just 
> incidentally...
> 
> I'll have to be more careful next time, sorry.
> ________________
> Miguel de  Benito.
> 
> 
> On Sat, Nov 6, 2010 at 23:35, Gubinelli Massimiliano <[email protected]> 
> wrote:
> Hi Miguel,
>  the fix is not quite correct. I've committed an alternative fix. The reasong 
> for the crash is the following (according to my understanding)
> in QTMInteractivePrompt::exec()
> 1. you create a temporary status bar
> 2. you add the prompt to the status bar (so it become children of the status 
> bar, according to docs)
> 3. you add the status bar to the window (so it become children of the window, 
> according to docs)
> 4. after execution you remove the status bar from the window (but its parent 
> remains the window)
> 5. when the status bar is released (somewhere, somehow) it tries to release 
> the interactive prompt which is allocated on the stack (and  already freed) 
> so you get the crash.
> 
> My solution is to reset the parent of the interactive prompt and to 
> explicitly delete the temporary status bar. Usually if you allocate an object 
> you have to be sure that it will be deallocated at appropriate time. Maybe 
> put comments to signal when you think it will be most probably deallocated.
> 
> 
> Best
> max
> 
> On 6 nov. 2010, at 19:20, Miguel de Benito Delgado wrote:
> 
>> It looks like I'm on a roll! ;) First the fix, in case you don't have time 
>> to waste on my ramblings:
>> 
>> File qt_dialogues.cpp, line 718 onward, change to:
>> 
>>   QTMInteractivePrompt* _prompt = new QTMInteractivePrompt(label, items, 
>> to_qstring(it->type), tm_mainwindow());
>>      
>>   if (_prompt->exec() == QDialog::Accepted) {
>>     QString text = _prompt->currentText();
>>     ((qt_input_text_widget_rep*) int_input.rep) -> text = scm_quote 
>> (from_qstring (text));
>>     ((qt_input_text_widget_rep*) int_input.rep) -> cmd ();
>>   } else {
>>     // ((qt_input_text_widget_rep*) int_input.rep) -> text="#f";
>>   }
>>   delete _prompt;
>> }
>> 
>> And here's the bug: 
>> Take any document and manually create a fake autosave file (i.e. with the 
>> trailing tilde) which is newer.
>> Open the document in TeXmacs QT (svn), with the new interactive prompt and 
>> the option to show interactive messages on the status bar.
>> The shiny new interactive prompt kicks in, asks whether you want to load the 
>> newer autosaved file.
>> Say whatever you want, it crashes on you.
>> Seems like qt_tm_widget_rep::write is doing tw->removeWidget(old_canvas); 
>> and this kills because the QTMInteractivePrompt had been created on the 
>> stack and someone is trying to delete it. Or that's my guess.
>> 
>> Kind regards,
>> ________________
>> Miguel de  Benito.
>> _______________________________________________
>> Texmacs-dev mailing list
>> [email protected]
>> http://lists.gnu.org/mailman/listinfo/texmacs-dev
> 
> 
> _______________________________________________
> Texmacs-dev mailing list
> [email protected]
> http://lists.gnu.org/mailman/listinfo/texmacs-dev
> 
> 
> _______________________________________________
> Texmacs-dev mailing list
> [email protected]
> http://lists.gnu.org/mailman/listinfo/texmacs-dev

_______________________________________________
Texmacs-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/texmacs-dev

Reply via email to