Results 1 to 12 of 12

Thread: Signal emit causes segmentation fault

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2017
    Posts
    6
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Signal emit causes segmentation fault

    The reference is valid when I check it with the debugger. The backtrace is added to my previous message.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Signal emit causes segmentation fault

    I created a whole new test signal that contains an integer which is not connected anywhere and it still causes the exact same segmentation fault.
    The backtrace without the code helps very little.
    Please post the code that corresponds to the backtrace, and if it is not very long, post all of it, don't "meta code" it as it masks what you are doing wrong.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Aug 2017
    Posts
    6
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Signal emit causes segmentation fault

    The test signal is not connected anywhere. The crash still happens at the same function after emit which is

    Qt Code:
    1. // SIGNAL 0
    2. void LidarSub::test(int _t1)
    3. {
    4. void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
    5. QMetaObject::activate(this, &staticMetaObject, 0, _a);
    6. }
    To copy to clipboard, switch view to plain text mode 

    lidarsub.h:

    Qt Code:
    1. #ifndef LIDARSUB_H
    2. #define LIDARSUB_H
    3.  
    4. #include "observation.h"
    5. #include <QThread>
    6. #include <QObject>
    7.  
    8. #include <ace/Log_Msg.h>
    9.  
    10. #include <dds/DdsDcpsInfrastructureC.h>
    11. #include <dds/DdsDcpsPublicationC.h>
    12.  
    13. #include <dds/DCPS/Marked_Default_Qos.h>
    14. #include <dds/DCPS/Service_Participant.h>
    15. #include <dds/DCPS/WaitSet.h>
    16.  
    17. #include "dds/DCPS/StaticIncludes.h"
    18.  
    19. #include "/home/vtt/IDL/idl_lidar/lidarScanTypeSupportImpl.h"
    20.  
    21. class LidarSub: public QThread
    22. {
    23. Q_OBJECT
    24.  
    25. signals:
    26. void test(int i);
    27.  
    28. public:
    29. LidarSub();
    30. int create();
    31. void destroy();
    32. void lidarDataConverter(LidarScan::Observation newObs);
    33.  
    34. protected:
    35. virtual void run();
    36.  
    37. private:
    38. DDS::DomainParticipantFactory_var dpf_;
    39. DDS::DomainParticipant_var participant_;
    40. DDS::DataReader_var reader_;
    41. LidarScan::ObservationDataReader_var reader_i_;
    42.  
    43. int numOfRecObs_;
    44.  
    45. };
    46. #endif // LIDARSUB_H
    To copy to clipboard, switch view to plain text mode 


    lidarsub.cpp:

    Qt Code:
    1. #include "lidarsub.h"
    2.  
    3. #include <QDebug>
    4. #include <QThread>
    5.  
    6. #include <ace/Log_Msg.h>
    7.  
    8. #include <dds/DdsDcpsInfrastructureC.h>
    9. #include <dds/DdsDcpsPublicationC.h>
    10.  
    11. #include <dds/DCPS/Marked_Default_Qos.h>
    12. #include <dds/DCPS/Service_Participant.h>
    13. #include <dds/DCPS/WaitSet.h>
    14.  
    15. #include "dds/DCPS/StaticIncludes.h"
    16.  
    17. #include "/home/vtt/IDL/idl_lidar/lidarScanTypeSupportImpl.h"
    18. #include "/home/vtt/IDL/idl_lidar/DataReaderListenerImpl.h"
    19.  
    20.  
    21. using namespace DDS;
    22. using namespace std;
    23.  
    24. void LidarSub::lidarDataConverter(LidarScan::Observation newObs)
    25. {
    26. int i = 0;
    27. emit test(i); // <- This causes the segmentation fault
    28. }
    29.  
    30. LidarSub::LidarSub()
    31. {
    32. numOfRecObs_ = 0;
    33. }
    34.  
    35. int LidarSub::create()
    36. {
    37. // OpenDDS related code that initiates the DDS configuration. Can't publish this part of the code on this forum.
    38. // This should not affect anything else than the DDS communication.
    39. }
    40.  
    41.  
    42. void LidarSub::destroy()
    43. {
    44. TheServiceParticipant->shutdown();
    45. }
    46.  
    47. void LidarSub::run()
    48. {
    49. while (true) {
    50.  
    51. QThread::msleep(10);
    52. }
    53. }
    To copy to clipboard, switch view to plain text mode 


    DataReaderListenerImpl.cpp - function that is called when new data arrives through DDS
    handle_ is pointer to the instantiation of LidarSub class

    Qt Code:
    1. void DataReaderListenerImpl::on_data_available(DDS::DataReader_ptr reader)
    2. {
    3. LidarScan::ObservationDataReader_var reader_i =
    4. LidarScan::ObservationDataReader::_narrow(reader);
    5.  
    6. if ( !reader_i )
    7. {
    8. ACE_ERROR((LM_ERROR,
    9. ACE_TEXT("ERROR: %N:%l: on_data_available() -")
    10. ACE_TEXT(" _narrow failed!\n")));
    11. ACE_OS::exit(-1);
    12. }
    13.  
    14.  
    15. LidarScan::Observation newObs;
    16. DDS::SampleInfo info;
    17.  
    18. DDS::ReturnCode_t error = reader_i->take_next_sample(newObs, info);
    19.  
    20. if (error == DDS::RETCODE_OK)
    21. {
    22.  
    23. if ( info.valid_data )
    24. {
    25. if ( handle_ != NULL )
    26. {
    27. handle_->lidarDataConverter(newObs);
    28. }
    29. }
    30.  
    31. } else
    32. {
    33. ACE_ERROR((LM_ERROR,
    34. ACE_TEXT("ERROR: %N:%l: on_data_available() -")
    35. ACE_TEXT(" take_next_sample failed!\n")));
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Signal emit causes segmentation fault

    Does handle_ point to a valid object?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2017
    Posts
    6
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Signal emit causes segmentation fault

    Quote Originally Posted by wysota View Post
    Does handle_ point to a valid object?
    No, thank you! I had forgotten about setting the actual pointer. For some reason the DataReaderListenerImpl is able to call the lidarDataConverter() even though the pointer is not a valid object.
    Last edited by Martikai; 28th August 2017 at 11:59.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Signal emit causes segmentation fault

    It's a non-virtual function so it doesn't need a proper object to call it. But when you try accessing any data, you end up with reading garbage.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Seems that my emit doesn't emit the signal
    By roseicollis in forum Newbie
    Replies: 2
    Last Post: 19th January 2015, 16:05
  2. Please help!! Segmentation fault in Qt
    By jmalicke in forum Qt Programming
    Replies: 1
    Last Post: 23rd July 2014, 05:35
  3. a segmentation fault
    By yaohao@qtcentre in forum Qt Programming
    Replies: 4
    Last Post: 17th March 2011, 09:01
  4. Segmentation Fault
    By freekill in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2010, 15:31
  5. Segmentation Fault
    By Krish_ng in forum Qt Programming
    Replies: 8
    Last Post: 7th August 2007, 10:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.