我在Visual Studio 2017中创建了Qt5应用程序,此应用程序具有OpenDDS发布者。该程序构建成功,但是当我按“开始调试”时,该应用程序启动并立即崩溃。 我收到以下错误:
Exception thrown at 0x00007FFA77EC9129 in RobotController.exe: Microsoft C++ exception: CORBA::BAD_INV_ORDER at memory location 0x000000238017DA08.
我还尝试从命令提示符处执行该应用程序,该应用程序启动后变得无响应。 我已经执行了没有Qt应用程序的发布者,并且启动成功。当发布者代码不存在时,Qt应用程序将启动。
//Publisher for Robot Controller
#include "RobotController.h"
#include <QtWidgets/QApplication>
#include "dds/DdsDcpsInfrastructureC.h"
#include "dds/DdsDcpsPublicationC.h"
#include "dds/DCPS/Marked_Default_Qos.h"
#include "dds/DCPS/Service_Participant.h"
#include "dds/DCPS/WaitSet.h"
#include "dds/DCPS/StaticIncludes.h"
#include "DirectionTypeSupportImpl.h"
#include <iostream>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
RobotController w;
w.show();
try {
//Initialize DomainParticipantFactory
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
//Create DomainParticipant
DDS::DomainParticipant_var participant =
dpf->create_participant(0, // domain ID
PARTICIPANT_QOS_DEFAULT,
0, // No listener required
OpenDDS::DCPS::NO_STATUS_MASK);
if (!participant) {
std::cerr << "create_participant failed." << std::endl;
return 1;
}
Direction::NewDirTypeSupport_var sbts =
new Direction::NewDirTypeSupportImpl;
if (sbts->register_type(participant, "") != DDS::RETCODE_OK) {
std::cerr << "register_type failed." << std::endl;
return 1;
}
//Obtain type name and create topic, typename is passed
CORBA::String_var type_name = sbts->get_type_name();
DDS::Topic_var topic =
participant->create_topic("Direction",
type_name,
TOPIC_QOS_DEFAULT,
0, // No listener required
OpenDDS::DCPS::NO_STATUS_MASK);
if (!topic) {
std::cerr << "create_topic2 failed." << std::endl;
return 1;
}
//Creation of a publisher
DDS::Publisher_var pub =
participant->create_publisher(PUBLISHER_QOS_DEFAULT,
0, // No listener required
OpenDDS::DCPS::NO_STATUS_MASK);
if (!pub) {
std::cerr << "create_publisher failed." << std::endl;
return 1;
}
//Create the datawriter
DDS::DataWriter_var writer =
pub->create_datawriter(topic,
DATAWRITER_QOS_DEFAULT,
0, // No listener required
OpenDDS::DCPS::NO_STATUS_MASK);
if (!writer) {
std::cerr << "create_datawriter2 failed." << std::endl;
return 1;
}
//Create Position datawwriter
Direction::NewDirDataWriter_var message_writer =
Direction::NewDirDataWriter::_narrow(writer);
if (!message_writer) {
std::cerr << "_narrow failed!." << std::endl;
return 1;
}
//Add Position datareader statuscondition to condition queue
DDS::StatusCondition_var condition2 = writer->get_statuscondition();
condition2->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS);
DDS::WaitSet_var ws = new DDS::WaitSet;
ws->attach_condition(condition2);
while (true) {
DDS::PublicationMatchedStatus matches;
if (writer->get_publication_matched_status(matches) != DDS::RETCODE_OK) {
std::cerr << "get_publication_matched_status failed!, 2" << std::endl;
return 1;
}
if (matches.current_count >= 1) {
break;
}
//create condition
DDS::ConditionSeq conditions;
DDS::Duration_t timeout = { 60, 0 };
if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) {
std::cerr << "wait failed!" << std::endl;
return 1;
}
}
ws->detach_condition(condition2);
DDS::Duration_t timeout = { 30, 0 };
//Message topic 2
Direction::NewDir message;
message.ID = 1;
message.Forward = 1;
message.Backward = 0;
message.Left = 0;
message.Right = 0;
message.Stop = 0;
//Sending the message 10 times
for (int i = 0; i < 10; ++i) {
DDS::ReturnCode_t error = message_writer->write(message, DDS::HANDLE_NIL);
if (error != DDS::RETCODE_OK) {
std::cerr << "message publication failed!" << std::endl;
return 1;
}
}
if (message_writer->wait_for_acknowledgments(timeout) != DDS::RETCODE_OK) {
std::cerr << "wait_for_acknowledgments failed!, Position" << std::endl;
return 1;
}
// Clean-up!
participant->delete_contained_entities();
dpf->delete_participant(participant);
TheServiceParticipant->shutdown();
}
catch (const CORBA::Exception& e) {
e._tao_print_exception("Exception caught in main():");
return -1;
}
return a.exec();
}
我希望程序能够启动而不会崩溃,并且让发布者发送消息。