setPos() in a QGraphicsItem, finished the programm.
-
Hi all,
i have trouble with my code.I have a class it inherit from QGraphicsItem and it update the position.
I call the function render() in a gameloop (ca. 30 times a second). If i do this
i got the runtimeerror "The program has unexpectedly finished." If i set the Position in the constructor
it works, but i need to update it frequently.void Particle::render() { setPos(position.getX(),position.getY()); }
How can i update the Position frequently.
I hope the question is not too simple.
THX for help!
Greetings Meho -
@Mehonidas
please retry with a debugger attached and show the stackstrace. -
Hi raven,
thank you for respond.in debuging mode the following error appear:
"The inferior stopped because it received a signal from the Operating System.Signal name :
SIGSEGV
Signal meaning :
Segmentation fault"And here is the stack trace:
I hope this is what you want? If you need more just say it.0 QGraphicsItem::setPos(QPointF const&) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff79b9708
1 QGraphicsItem::setPos qgraphicsitem.h 495 0x4095c3
2 Particle::render particle.cpp 15 0x40b2dc
3 BombFactory::render bombfactory.cpp 42 0x40b6aa
4 Game::gameLoop game.cpp 111 0x407722
5 Game::qt_static_metacall moc_game.cpp 71 0x40c3ee
6 QMetaObject::activate(QObject*, int, int, void**) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b4d2a6
7 QTimer::timerEvent(QTimerEvent*) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b59622
8 QObject::event(QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b4e054
9 QApplicationPrivate::notify_helper(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff76ebc8c
10 QApplication::notify(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff76f0e56
11 QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b25c2d
12 QTimerInfoList::activateTimers() /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b721ad
13 ?? /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b72661
14 g_main_context_dispatch /lib/x86_64-linux-gnu/libglib-2.0.so.0 0x7ffff55aae04
15 ?? /lib/x86_64-linux-gnu/libglib-2.0.so.0 0x7ffff55ab048
16 g_main_context_iteration /lib/x86_64-linux-gnu/libglib-2.0.so.0 0x7ffff55ab0ec
17 QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b7298c
18 QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b2496b
19 QCoreApplication::exec() /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b2b0e1
20 main main.cpp 15 0x407048The program stop at this lines:
inline void QGraphicsItem::setPos(qreal ax, qreal ay) { setPos(QPointF(ax, ay)); }
Thx for help!
Greetings Meho -
Just for test.
If u set timer to 2 secs or slower, does it still crash? -
I tried it with a fixed frame rate of 1 und 2 frames per second.
I got the same error :-(I have a class "Player", it inherits from QObject and QGraphicsPixmapItem.
In this class it works fine.
I tried to adapted as much as possible, but no success.Thanks for your help!
-
hi
ok. so its not because the timer call the render functions while a setpos is already in progress.Have you tried with other function besides setPos to find out if only for such operation?
Also, is there any chance you cause infinite repaints, like calling setpos in paint so paint is called again. ?
-
@Mehonidas
Two ideas:- Any possibility you accidentally destroyed the item, and setPos is called on a destroyed object? Check by setting a breakpoint in your Item's destructor
- Is the timer running in the application's main thread?
-
Hi,
thank you for your help!I uploaded my code:
https://mega.nz/#!5EF12RKA!LkoWvUF4ABpB6XcMrk1qFWWw4OtzbnUxarWgUqGEg4g
I am a beginner, so please dont hit me for my bad code style!Have you tried with other function besides setPos to find out if only for such operation?
The function setPos() works fine in the constructor of the class, but not in any other function.
I called the function with the key T, but the programm crashed too!Also, is there any chance you cause infinite repaints, like calling setpos in paint so paint is called again. ?
I implemented the paint function but i use the setPos() function only at one position in the class!
Any possibility you accidentally destroyed the item, and setPos is called on a destroyed object?
Check by setting a breakpoint in your Item's destructorNo the destructor of class Particle is not called!
Is the timer running in the application's main thread?
I have only two threads:
QXcbEventReader-Thread
Bomberman-Thread
and the loopTimer (gameloop) is running in Bomberman-Thread (programm thread)Thank you for your help!
Has somebody any other idea? -
AHHHH,
OK i found the mistake!
It is so embarrassing!I created 1000 particles for a particle system and put it in a list, for better handling.
In a function i use a for-loop to iterate about the list and call the render function of each particle. I began at 0 and used the "<=" statement. I iterated one step too much!I confused that the debugger stopped at the setPos() function, so i searched the mistake at the wrong position!
Thank you very much for your help and time!
Bye Meho -
Hehe good found :)
4/10