Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » TabCtrl » TabCtrl crash in debug mode when using remove method
TabCtrl crash in debug mode when using remove method [message #23476] Thu, 22 October 2009 00:14 Go to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hello,

In my app I use TabCtrl. I add and remove tabs dynamically but there seems to be a bug: when the app is compiled in DEBUG mode it crashes when the last tab gets removed.

I looked in the debugger and it crashes in the following sequence:

Upp::AssertFailed (file=0x8296f14 "/home/didier/upphg/uppsrc/Core/Vcont.h", line=17, cond=0x8296f79 "i >= 0 && i < items") at /home/didier/upphg/uppsrc/Core/Util.cpp:86
Upp::Vector<void*>::Get (this=0xbfffdbe8, i=0) at /home/didier/upphg/uppsrc/Core/Vcont.h:17
Upp::Vector<void*>::operator[] (this=0xbfffdbe8, i=0) at /home/didier/upphg/uppsrc/Core/Vcont.h:32
Upp::Array<Upp::TabCtrl::Item>::Get (this=0xbfffdbe4, i=0) at /home/didier/upphg/uppsrc/Core/Vcont.h:132
Upp::Array<Upp::TabCtrl::Item>::operator[] (this=0xbfffdbe4, i=0) at /home/didier/upphg/uppsrc/Core/Vcont.h:144
Upp::TabCtrl::ScrollInto (this=0xbfffdb78, i=0) at /home/didier/upphg/uppsrc/CtrlLib/TabCtrl.cpp:257
Upp::TabCtrl::Layout (this=0xbfffdb78) at /home/didier/upphg/uppsrc/CtrlLib/TabCtrl.cpp:139
Upp::TabCtrl::Remove (this=0xbfffdb78, i=0) at /home/didier/upphg/uppsrc/CtrlLib/TabCtrl.cpp:401
testOnglet::closeOnglet (this=0xbfffda5c) at /home/didier/upphg/MyApps/testOnglet/main.cpp:34


The vector::get() statement crashes because we try to remove element '0' while there are no more elements in vector (items = 0)


When compiling in OPTIMAL mode, everything seems to be OK.

I joined a test app:
compil in DEBUG, Launch and press the close button 3 times (until last tab gets removed)
==> crash when trying to close last tab ?????


Re: TabCtrl crash in debug mode when using remove method [message #23486 is a reply to message #23476] Thu, 22 October 2009 21:39 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
I found the bug Smile

in TabCtrl.cpp Line 139

replace
ScrollInto(sel);

with
if (sel < tab.GetCount())	ScrollInto(sel);


Re: TabCtrl crash in debug mode when using remove method [message #23504 is a reply to message #23486] Sat, 24 October 2009 10:48 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thank you, indeed, empty TabCtrl was not supported...

Two other notes about the code:

It leaves memory leaks. In real code, I think for dynamic tabs, you would want to use Array to store tabs. Remember, avoid 'new' and 'delete' whenever possible...

Also, setting frame for StatusBar breaks the visuals for bottom right resizing handle.

Mirek
Re: TabCtrl crash in debug mode when using remove method [message #23506 is a reply to message #23504] Sat, 24 October 2009 20:55 Go to previous message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Mirek,

Thanks for your reply.

Quote:

It leaves memory leaks. In real code, I think for dynamic tabs, you would want to use Array to store tabs. Remember, avoid 'new' and 'delete' whenever possible...

The code presented in the test case was only to demonstrate the problem and is "no good" for anything else Razz
In my real app all the delete stuff is managed and absolutely necessary.

Quote:

Also, setting frame for StatusBar breaks the visuals for bottom right resizing handle.

I have to admit that this one has been tickling me for a bunch of time. But since it wasn't really critical I never really took time to solve it. I guess you saved me time, thanks Smile

Previous Topic: TabCtrl FIX
Next Topic: Disappearing tabs in TabCtrl
Goto Forum:
  


Current Time: Thu Mar 28 12:09:14 CET 2024

Total time taken to generate the page: 0.01118 seconds