JAUS ++教程程序出错

时间:2015-06-21 17:52:22

标签: c++ exception visual-studio-2012 memory-leaks jaus++

我最近在Microsoft Visual Studio 2012中安装了JAUS ++(http://active-ist.sourceforge.net/jaus++.php)和Boost库。我正在尝试运行第一个JAUS ++教程,在这里找到(http://active-ist.sourceforge.net/jaus++/examples/tutorial_01.html)但是,在调试期间,它运行成:

" JausTest.exe中0x77064598处的未处理异常:Microsoft C ++异常:内存位置0x0024F240处的std :: bad_alloc。"

然后,它会创建一个断点。然后,如果我点击继续,则会出现第二个错误:

" JausTest.exe中0x647C51C4(msvcr110.dll)的未处理异常:0xC0000005:访问冲突读取位置0x0000006C。"

似乎打破了:" discoveryService = component.DiscoveryService();"因为下一行" discoveryService-> SetSubsystemIdentification(JAUS :: Subsystem :: Vehicle," Robot");",表示它将是下一行代码执行恢复时。

我很惊讶这是因为我直接从教程中复制了代码。我想知道这些库是否有问题?

非常感谢任何见解。

以下是调试消息

'JausTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Cannot find or open the PDB file.
First-chance exception at 0x77064598 in JausTest.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0024FAA0.
First-chance exception at 0x77064598 in JausTest.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0024F240.
First-chance exception at 0x77064598 in JausTest.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
Unhandled exception at at 0x77064598 in JausTest.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0024F240.
The program '[5192] JausTest.exe' has exited with code 0 (0x0).

以下是代码:

#include "stdafx.h"
#include <jaus/core/component.h>
#include <cxutils/keyboard.h>
#include <iostream>



int main(int argc, char* argv[])
{
    // Create a component.  By default a component
    // has all the services of the Core Service set:
    // - Transport (JUDP)
    // - Control
    // - Discovery
    // - Events
    // - Liveness
    // - Time
    // - Management
    JAUS::Component component;

    // The Transport service is used to send
    // and receive messages to other JAUS components.  All
    // other services use the Transport service.  The
    // default transport type for JAUS++ is UDP communication
    // using the JUDP class.

    // The Discovery service is used to find
    // other JAUS components and services on the 
    // network using the Transport service.  In JAUS++
    // Discovery will automatically find these components,
    // make connections to them, and keep track of what
    // services they have.

    //  The first thing we must do for a component is
    //  configure its identification.  This is done by
    //  using the Discovery Service.  Get a pointer
    //  to the service:
    JAUS::Discovery* discoveryService = NULL;
    //discoveryService = (JAUS::Discovery*)component.GetService(JAUS::Discovery::Name);
    //  Alternative method:
    discoveryService = component.DiscoveryService();

    // Set the type of subsystem the component is for.  Subsystem
    // types available are currently Vehicle, or OCU.  The string
    // name "Robot" represents the type or category of platform.
    // You must set the subsystem identification before you will be
    // able to initialize your component.
    discoveryService->SetSubsystemIdentification(JAUS::Subsystem::Vehicle,
                                                 "Robot");
    // You can also set identification information for the component
    // and node that it is on.
    discoveryService->SetNodeIdentification("Primary Computer");
    discoveryService->SetComponentIdentification("Baseline");

    // Now that we have setup our identification information we
    // can initialize our component.  First, create the
    // component ID.
    JAUS::Address componentID(1000, 1, 1);
    // Initialize!
    std::cout << "Initializing component...";
    if(component.Initialize(componentID) == false)
    {
        std::cout << "Failed to initialize component [" << componentID.ToString() << "]\n";
        return 0;
    }
    std::cout << "Success!\n";

    // Now go into your main computer loop until the
    // component has been told to shutdown.
    JAUS::Time::Stamp displayStatusTimeMs = JAUS::Time::GetUtcTimeMs();
    while(true)
    {
        // Let's check the "state" of our component. This
        // is done using the Management service.  
        // A component can be in the following states:
        // - Initialized
        // - Ready
        // - Standby
        // - Shutdown
        // - Failure
        // - Emergency
        JAUS::Management* managementService = NULL;
        //managementService = (JAUS::Management*)component.GetService(JAUS::Management::Name);
        // Alternative method:
        managementService = component.ManagementService();
        if(managementService->GetStatus() == JAUS::Management::Status::Shutdown)
        {
            // Exit program.
            break;
        }
        if(JAUS::Time::GetUtcTimeMs() - displayStatusTimeMs > 500)
        {
            std::cout << "======================================================\n";
            // Print status of the service.
            managementService->PrintStatus(); std::cout << std::endl;

            displayStatusTimeMs = JAUS::Time::GetUtcTimeMs();
        }

        if(CxUtils::GetChar() == 27)
        {
            break;
        }

        CxUtils::SleepMs(1);
    }

    // Shutdown your component completely.  Any
    // services added or belonging to the component
    // will be deleted.
    component.Shutdown();

    return 0;
}

0 个答案:

没有答案