PDA

View Full Version : Multi-thread related problem,help me



mendynew
31st October 2008, 03:02
I use Qt graphics view frame to display, because of plenty of items on views, I use new thread to create all items,add them to scene, and set their positions. The scene is created in main thread, after all items created, slot in main thread will invoked. Scene will be added to view and begin to display.
The program works well on Qt 4.2.2. But when I switch to Qt 4.4.0, some break point triggered. It seems it's the problem of multi-thread, when I create the items in main thread, there will be no problem.
The break point is triggered when I'm trying to set the item's position.
The call stack when is below:

-------------------------------------------------------------------------------------------------------
ntdll.dll!7c901230()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!7c96c943()
ntdll.dll!7c96cd80()
ntdll.dll!7c960af8()
> msvcp80d.dll!std::char_traits<char>::_Copy_s(char * _First1=0x0001eedc, unsigned int _Size_in_bytes=79424784, const char * _First2=0x104fef1d, unsigned int _Count=79425020) Line 575 + 0x16 bytes C++
msvcr80d.dll!unaligned_memcmp(const unsigned char * bLHS=0x7c85e9cf, const unsigned char * bRHS=0x01880000, unsigned int siz=1073741920) + 0x3a3 bytes C
04bbed74()
msvcr80d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x0431b188) Line 2072 C++
msvcr80d.dll!realloc_help(void * pUserData=0x0431b188, unsigned int * pnNewSize=0x04bbee18, int nBlockUse=1, const char * szFileName=0x00000000, int nLine=0, int fRealloc=1) Line 713 + 0x9 bytes C++
msvcr80d.dll!_realloc_dbg(void * pUserData=0x0431b188, unsigned int nNewSize=32, int nBlockUse=1, const char * szFileName=0x00000000, int nLine=0) Line 973 + 0x1b bytes C++
msvcr80d.dll!realloc(void * pUserData=0x0431b188, unsigned int nNewSize=32) Line 883 + 0x13 bytes C++
QtCored4.dll!qRealloc(void * ptr=0x0431b188, unsigned int size=32) Line 45 + 0xe bytes C++
QtCored4.dll!QListData::realloc(int alloc=3) Line 91 + 0x16 bytes C++
QtCored4.dll!QListData::append() Line 114 C++
QtGuid4.dll!QList<QRectF>::append(const QRectF & t={...}) Line 402 + 0xd bytes C++
QtGuid4.dll!QList<QRectF>Operator<<(const QRectF & t={...}) Line 280 + 0x13 bytes C++
QtGuid4.dll!QGraphicsScene::update(const QRectF & rect={...}) Line 2819 C++
QtGuid4.dll!QGraphicsScene::itemUpdated(QGraphicsI tem * item=0x043d47b4, const QRectF & rect={...}) Line 4170 C++
QtGuid4.dll!QGraphicsItemPrivate::updateHelper(con st QRectF & rect={...}, bool force=false) Line 2939 C++
QtGuid4.dll!QGraphicsItemPrivate::fullUpdateHelper () Line 2949 C++
QtGuid4.dll!QGraphicsItem::setPos(const QPointF & pos={...}) Line 2044 C++
QtGuid4.dll!QGraphicsItem::setPos(double ax=150.00000000000000, double ay=0.00000000000000000) Line 362 + 0x2d bytes C++
netlistviewerd.dll!BlockItem::setPosition(float x=150.00000, float y=0.00000000) Line 106 C++
netlistviewerd.dll!NetlistPainteraintLayerByLayer( int & x=150, QMap<int,LayerRectangle> & pageLayerRects={...}, QMap<int,QList<netlist_viewer::dnodeBlock> > & finalPage={...}, int & maxHeight=0, std::map<int,std::list<netlist_viewer::NlvPointF,std::allocator<netlist_viewer::NlvPointF> >,std::less<int>,std::allocator<stdair<int const ,std::list<netlist_viewer::NlvPointF,std::allocator<netlist_viewer::NlvPointF> > > > > & firstLayerInNets=[0](), std::map<int,std::list<netlist_viewer::NlvPointF,std::allocator<netlist_viewer::NlvPointF> >,std::less<int>,std::allocator<stdair<int const ,std::list<netlist_viewer::NlvPointF,std::allocator<netlist_viewer::NlvPointF> > > > > & lastLayerOutNets=[0](), int inoutLayerOption=3) Line 1850 C++
netlistviewerd.dll!NetlistPainteraintPage(int pageNum=1) Line 2273 C++
netlistviewerd.dll!NetlistPainteraintMultiPage(net list_viewer::ViewType viewType=RTLVIEW) Line 1790 C++
netlistviewerd.dll!NetlistPainteraintNetlist(netli st_viewer::ViewType viewType=RTLVIEW, netlist_viewer::PageType pageType=MULTIPAGE) Line 58 C++
netlistviewerd.dll!PaintNetlistThread::run() Line 66 C++
QtCored4.dll!QThreadPrivate::start(void * arg=0x04362cd8) Line 235 C++
msvcr80d.dll!_callthreadstartex() Line 348 + 0xf bytes C
msvcr80d.dll!_threadstartex(void * ptd=0x042bb840) Line 331 C
kernel32.dll!7c80b683()
ntdll.dll!7c9106eb()
---------------------------------------------------------------------------------------------------

caduel
31st October 2008, 08:04
Only the gui thread my use QWidgets (and subclasses). Adding a QGraphicsItem to a scene (finally) calls the QGraphicsView(s) displaying that scene. So in all probability you may not do that in a separate thread.

mendynew
3rd November 2008, 04:02
Only the gui thread my use QWidgets (and subclasses). Adding a QGraphicsItem to a scene (finally) calls the QGraphicsView(s) displaying that scene. So in all probability you may not do that in a separate thread.

Oh, the case you mention is not in my program. Because when I add item to scene, the scene is not added to view yet. so it won't try to "calls the QGraphicsView(s) displaying that scene". The design on 4.2.2 works well, I don't know whether there's any modification related with this problem on 4.4.0.