Hello!
So the game works just fine but when i add the code which creates hp, hunger and thirst bar for my game, the game doesn't load on normal run (and it crashes), but it does fully load when i run the debugger and it works just fine.

this is the code that i run in game.cpp:
Qt Code:
  1. void Game::drawBars()
  2. {
  3. bars = new Bars();
  4. scene->addItem(bars->hp);
  5. scene->addItem(bars->hunger);
  6. scene->addItem(bars->thirst);
  7. }
To copy to clipboard, switch view to plain text mode 

This is Bars.h file
Qt Code:
  1. #ifndef BARS_H
  2. #define BARS_H
  3.  
  4. #include <QGraphicsRectItem>
  5. #include <QGraphicsItem>
  6. #include <QObject>
  7.  
  8. class Bars: public QObject{
  9. Q_OBJECT
  10. public:
  11. Bars();
  12. QLineF line;
  13. QLineF dist;
  14. void setPosition();
  15. private:
  16. int hp_amount;
  17. int hunger_amount;
  18. int thirst_amount;
  19. float size;
  20. float hp_height;
  21. float hunger_height;
  22. float thirst_height;
  23. };
  24.  
  25. #endif // BARS_H
To copy to clipboard, switch view to plain text mode 

This is Bars.cpp file
Qt Code:
  1. Bars::Bars()
  2. {
  3. hp_amount = 1400;
  4. hunger_amount = 1400;
  5. thirst_amount = 1400;
  6. QVector<QPointF> hp_points,hunger_points,thirst_points;
  7. hp_points << QPointF(1,0) << QPointF(2,0) << QPointF(2.33,1) << QPointF(2.66,2) << QPointF(3,3) << QPointF(3,4) << QPointF(2.66,5) << QPointF(2.33,6) << QPointF(2,7) << QPointF(1,7) << QPointF(0.66,6) << QPointF(0.33,5) << QPointF(0,4) << QPointF(0,3) << QPointF(0.33,2) << QPointF(0.66,1);
  8. hunger_points << QPointF(-1,0) << QPointF(0,0) << QPointF(-0.33,1) << QPointF(-0.66,2) << QPoint(-1,3) << QPoint(-1,4) << QPointF(-0.66,5) << QPointF(-0.33,6) << QPointF(0,7) << QPoint(-1,7) << QPointF(-1.33,6) << QPointF(-1.66,5) << QPoint(-2,4) << QPointF(-2,3) << QPointF(-1.66,2) << QPointF(-1.33,1);
  9. thirst_points << QPoint(3,0) << QPoint(4,0) << QPointF(4.33,1) << QPointF(4.66,2) << QPoint(5,3) << QPoint(5,4) << QPointF(4.66,5) << QPointF(4.33,6) << QPointF(4,7) << QPointF(3,7) << QPointF(3.33,6) << QPointF(3.66,5) << QPointF(4,4) << QPointF(4,3) << QPointF(3.66,2) << QPointF(3.33,1);
  10.  
  11. line.setPoints(hunger_points[0], hp_points[0]);
  12. dist.setPoints(hp_points[0], hp_points[1]);
  13. size = game->getViewHeight()/57;
  14.  
  15. for(int i=0;i<hp_points.size();i++){
  16. hp_points[i] *= size;
  17. hunger_points[i] *= size;
  18. thirst_points[i] *= size;
  19. }
  20.  
  21. hp = new QGraphicsPolygonItem(QPolygonF(hp_points));
  22. hunger = new QGraphicsPolygonItem(QPolygonF(hunger_points));
  23. thirst = new QGraphicsPolygonItem(QPolygonF(thirst_points));
  24.  
  25. hp_height = hp->boundingRect().height();
  26. hunger_height = hunger->boundingRect().height();
  27. thirst_height = thirst->boundingRect().height();
  28.  
  29. setPosition();
  30.  
  31. hp->setBrush(QBrush("#f44047"));
  32. hunger->setBrush(QBrush("#efbc12"));
  33. thirst->setBrush(QBrush("#00a8f3"));
  34. //hp->setPen(Qt::NoPen);
  35. //hunger->setPen(Qt::NoPen);
  36. //thirst->setPen(Qt::NoPen);
  37. hp->setZValue(16);
  38. }
  39.  
  40. void Bars::setPosition()
  41. {
  42. game->scene->removeItem(hp);
  43. game->scene->addItem(hp);
  44. game->scene->removeItem(hunger);
  45. game->scene->addItem(hunger);
  46. game->scene->removeItem(thirst);
  47. game->scene->addItem(thirst);
  48.  
  49. hp->setPos(game->hotbarSlots->slot[8]->x()+game->hotbarSlots->slot[8]->boundingRect().width()+(game->getViewWidth()*0.175)/2-dist.length()/2, game->hotbarSlots->slot[8]->y()+game->hotbarSlots->slot[8]->boundingRect().width()-hp_height);
  50. hunger->setPos(hp->x()-line.length()/2,game->hotbarSlots->slot[8]->y()+game->hotbarSlots->slot[8]->boundingRect().width()-hunger_height);
  51. thirst->setPos(hp->x()+line.length()/2,game->hotbarSlots->slot[8]->y()+game->hotbarSlots->slot[8]->boundingRect().width()-thirst_height);
  52. }
To copy to clipboard, switch view to plain text mode 

Any help or advice is appreciated !!!