0
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -177935456 (LWP 5483)]
0xf79ff2ca in activemq::core::ActiveMQSessionExecutor::dispatch (this=0xf4b04bc0, 
    dispatch=@0xf564e240) at activemq/core/ActiveMQSessionExecutor.cpp:129
129 activemq/core/ActiveMQSessionExecutor.cpp: No such file or directory.
    in activemq/core/ActiveMQSessionExecutor.cpp
Current language:  auto; currently c++

どうすればこれを修正できますか? もっとコードが必要ですか?どこで失敗するのかわからない?失敗した場所を見つけるにはどうすればよいですか?

どこにダンプしますか?

編集:
ここにコードがあります:

std::string ActiveMQWrapper::get(){
    Connection* connection;
    Session* session;
    Destination* destination;
    MessageConsumer* consumer;

    try {
        std:string brokerURI = "tcp://localhost:61613?wireFormat=stomp";
        auto_ptr<ConnectionFactory> connectionFactory(ConnectionFactory::createCMSConnectionFactory( brokerURI ) );
        connection = connectionFactory->createConnection();
        connection->start();

        session = connection->createSession( Session::AUTO_ACKNOWLEDGE );
        destination = session->createQueue( "TEST.Prototype" );
        consumer = session->createConsumer( destination );
        TextMessage* textMessage =
            dynamic_cast< TextMessage* >( consumer->receive() );

        string text = "";

        if( textMessage != NULL ) {
            text = textMessage->getText();
        } else {
            text = "NOT A TEXTMESSAGE!";
        }

        try{
            if( destination != NULL ) delete destination;
        }catch (CMSException& e) { e.printStackTrace(); }
        destination = NULL;

        try{
            if( consumer != NULL ) delete consumer;
        }catch (CMSException& e) { e.printStackTrace(); }
        consumer = NULL;

        // Close open resources.
        try{
            if( session != NULL ) session->close();
            if( connection != NULL ) connection->close();
        }catch (CMSException& e) { e.printStackTrace(); }

        // Now Destroy them
        try{
            if( session != NULL ) delete session;
        }catch (CMSException& e) { e.printStackTrace(); }
        session = NULL;

        try{
            if( connection != NULL ) delete connection;
        }catch (CMSException& e) { e.printStackTrace(); }
        connection = NULL;

         return text.c_str();

    } catch( CMSException& e ) {
        e.printStackTrace();
    }
}
4

2 に答える 2

1

この問題に対する答えを探しているときにこれに出くわし、正しい解決策を発見しました。最初に ActiveMQ-CPP ライブラリを適切に初期化する必要があります。

activemq::library::ActiveMQCPP::initializeLibrary();

終了したら、忘れずにシャットダウンしてください。

activemq::library::ActiveMQCPP::shutdownLibrary();

実際には、OP がリンクした Web ページの一部です: http://activemq.apache.org/cms/example.html

于 2015-07-01T21:49:07.203 に答える
-1

削除に関するテストから(これは完全に不要です。NULLでの削除は完全に定義されています)、connectionなどはNULLになる可能性があると収集します。ただし、上記では、それらを使用する前に NULL をチェックしていません。そのため、そのうちの 1 つが NULL である可能性があるため、アクセスするとセグメンテーション違反が発生します。

また: ConnectionFactory::createCMSConnectionFactory から返されたポインタは で割り当てられていnewますか? そうでなければ、それらを に格納するのauto_ptrは正しいことではないからです。

さらに、ConnectionFactoryインスタンス化した時点で型が定義されていますか (単に (前方に) 宣言されているのではなく) auto_ptr? auto_ptr不完全な型 (宣言されただけで、まだ定義されていない型など) のインスタンス化は未定義の動作であり、セグメンテーション違反につながる可能性があるためです。

それらは私が見る可能性です。あなたが示したコードだけでこれ以上言う方法はありません。デバッガーを使用してシングルステップ実行し、セグメンテーション違反が発生する場所を確認する必要があります。

于 2011-11-15T23:35:12.553 に答える