PDGD_GlobalDataLayerInstance.C not found

   2355   1   1
User Avatar
Member
3 posts
Joined: 9月 2023
Offline
Hi, I created a simple project to try out the HAPI library.

This is the code:

#include <iostream>
#include <HAPI/HAPI.h>
#include <HAPI/HAPI_Common.h>


void CheckHAPIError(HAPI_Result result, const HAPI_Session& session) {
    if (result != HAPI_RESULT_SUCCESS) {
        int bufferLength;
        HAPI_GetStatusStringBufLength(&session, HAPI_STATUS_CALL_RESULT, HAPI_STATUSVERBOSITY_ERRORS, &bufferLength);

        char* statusString = new char[bufferLength];
        HAPI_GetStatusString(&session, HAPI_STATUS_CALL_RESULT, statusString, bufferLength);

        std::cerr << "HAPI error: " << statusString << std::endl;
        delete[] statusString;
        exit(1);
    }
}

int main()
{
    std::cout << "Initializing Houdini Engine session..." << std::endl;

    HAPI_Session session;
    HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();

    HAPI_Result result;

    result = HAPI_CreateInProcessSession(&session);
    std::cout << "HAPI_CreateInProcessSession result: " << result << std::endl;
    CheckHAPIError(result, session);

    result = HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr);
    std::cout << "HAPI_Initialize result: " << result << std::endl;
    CheckHAPIError(result, session);


    std::cout << "Cleaning up Houdini Engine session..." << std::endl;
    result = HAPI_Cleanup(&session);
    std::cout << "HAPI_Cleanup result: " << result << std::endl;
    CheckHAPIError(result, session);

    std::cout << "Finished successfully." << std::endl;

    return 0;
}

This builds without an issue.
When the program is ran, this is its output:

Initializing Houdini Engine session...
HAPI_CreateInProcessSession result: 0
HAPI_Initialize result: 0
Cleaning up Houdini Engine session...
HAPI_Cleanup result: 0
Finished successfully.

Then this exception happens (See attachment).

The exception is thrown from libPDGD.dll.

Have I forgot to do clean up something in my code snippet?

Attachments:
Screenshot (13).png (287.1 KB)

User Avatar
Member
3 posts
Joined: 3月 2023
Offline
What I was missing were the calls HAPI_Shutdown and HAPI_CloseSession. The code works without calling the HAPI_CloseSession as well. I am not sure why though.

Full code:
#include <iostream>
#include <HAPI/HAPI.h>
#include <HAPI/HAPI_Common.h>

void CheckHAPIError(HAPI_Result result, const HAPI_Session& session) {
    if (result != HAPI_RESULT_SUCCESS) {
        int bufferLength;
        HAPI_GetStatusStringBufLength(&session, HAPI_STATUS_CALL_RESULT, HAPI_STATUSVERBOSITY_ERRORS, &bufferLength);

        char* statusString = new char[bufferLength];
        HAPI_GetStatusString(&session, HAPI_STATUS_CALL_RESULT, statusString, bufferLength);

        std::cerr << "HAPI error: " << statusString << std::endl;
        delete[] statusString;
        exit(1);
    }
}

int main()
{
    std::cout << "Initializing Houdini Engine session..." << std::endl;

    HAPI_Session session;
    HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();

    HAPI_Result result;

    result = HAPI_CreateInProcessSession(&session);
    std::cout << "HAPI_CreateInProcessSession result: " << result << std::endl;
    std::cout << "Session handle: " << session.id << std::endl;

    CheckHAPIError(result, session);

    result = HAPI_Initialize(&session, &cookOptions, false, -1, nullptr, nullptr, nullptr, nullptr, nullptr);
    std::cout << "HAPI_Initialize result: " << result << std::endl;
    CheckHAPIError(result, session);


  
    std::cout << "Shut down HAPI session..." << std::endl;
    result = HAPI_Shutdown(&session);
    std::cout << "HAPI_Shutdown result: " << result << std::endl;

    std::cout << "Cleaning up Houdini Engine session..." << std::endl;
    result = HAPI_Cleanup(&session);
    std::cout << "HAPI_Cleanup result: " << result << std::endl;
    CheckHAPIError(result, session);

    std::cout << "Closing session..." << std::endl;
    result = HAPI_CloseSession(&session);
    std::cout << "HAPI_CloseSession result: " << result << std::endl;


    std::cout << "Finished successfully." << std::endl;
    return 0;
}


It is easy to miss. The description from function documentation explains the rationale behind this:


/// @brief  When using an in-process session, this method **must** be called in
///         order for the host process to shutdown cleanly. This method should
///         be called before ::HAPI_CloseSession(). 
///
///         @note This method should only be called before exiting the program,
///         because HAPI can no longer be used by the process once this method
///         has been called.
///
/// @ingroup Sessions
///
/// @param[in]      session
///                 The session of Houdini you are interacting with.
///                 See @ref HAPI_Sessions for more on sessions.
///                 Pass NULL to just use the default in-process session.
///                 <!-- default NULL -->
///
HAPI_DECL HAPI_Shutdown( const HAPI_Session * session );

/// @brief  Closes a session. If the session has been established using
///         RPC, then the RPC connection is closed.
///
/// @ingroup Sessions
///
/// @param[in]     session
///                The HAPI_Session to close. After this call, this
///                session is invalid and passing it to HAPI calls other
///                than ::HAPI_IsSessionValid() may result in undefined
///                behavior.
///
HAPI_DECL HAPI_CloseSession( const HAPI_Session * session );
Edited by Drobek - 2024年7月4日 01:35:11
  • Quick Links