Search - User list
Full Version: INVALID_SESSION when trying to initialize Houdini Engine with default in-process session in C#
Root » Houdini Engine API » INVALID_SESSION when trying to initialize Houdini Engine with default in-process session in C#
MsOddball
I am trying to initialize Houdini Engine in a C# built host with the default in-process session.
When running the code I keep getting HAPI_RESULT_INVALID_SESSION as result. I know the .dll is correctly
set up since I can call other functions correctly (such as HAPI_GetEnvInt()). How should I initialize Houdini
Engine with the default in-process session?

 
[DllImport(HoudiniVersion.HAPI_LIBRARY, CallingConvention = CallingConvention.Cdecl)]
private static unsafe extern HAPI_Result
HAPI_Initialize(
HAPI_Session* session,
ref HAPI_CookOptions cook_options,
[MarshalAs(UnmanagedType.U1)] bool use_cooking_thread,
int cooking_thread_stack_size,
string houdini_environment_files,
string otl_search_path,
string dso_search_path,
string image_dso_search_path,
string audio_dso_search_path);

public struct HAPI_Session
{
public HAPI_SessionType type;

public HAPI_SessionId id;
};

private static bool initialize()
{
...

HAPI_CookOptions cook_options = getCookOptions();

unsafe
{
status_code = HAPI_Initialize(
null, ref cook_options, true, -1, "", null, null, null, null);
}

...
}
dpernuit
Hi,

Even when using the default in-process session, you still have to call CreateInProcess() session before HAPI_Initialize.

HAPI_Session session;
HAPI_CreateInProcessSession( &session );
    
unsafe
{
    status_code = HAPI_Initialize(( &session,
                                 &cookOptions,
                                 true,
                                 -1,
                                 nullptr,
                                 nullptr,
                                 nullptr,
                                 nullptr,
                                 nullptr ) );
}
MsOddball
Alright.

Then I have another problem. The function HAPI_CreateInProcessSession does not exist in the libHARC32.dll.
At least not that I can see by using VSs dumpbin. The function does exist in libHAPI.dll but since I get the
BadImageFormatException when trying to use that .dll instead of libHARC32.dll I guess it is not made for a x86 application?
Or am I doing something wrong when writing the code?

// HoudiniVersion.HAPI_LIBRARY = "libHARC32.dll" or "libHAPI.dll"
[DllImport(HoudiniVersion.HAPI_LIBRARY, CallingConvention = CallingConvention.Cdecl)]
private static extern HAPI_Result
HAPI_CreateInProcessSession(out HAPI_Session session);

private static bool initialize()
{
...

HAPI_Session session;
HAPI_CreateInProcessSession(out session);

...
}
seelan
Yes, you'll need to import libHAPIL.dll as that contains all the HAPI function's you'll need to import.

If you want a C# reference, you can check out the Houdini Engine for Unity version 2, available on recent Houdini 16.5 daily and production builds. See more info here: http://www.sidefx.com/docs/unity/index.html [www.sidefx.com]
MsOddball
What would you recommend me to do if my application is x86 and not x64?
I only get a BadImageFormatException when I am trying to load the libHAPIL.dll.

libHARC32.dll works fine but with all the others I get the same exception which makes
me think that the others are x64 dlls?

Is there a reason why the CreateInProcess() function is not included in the 32bits version?
dpernuit
Hi,

You're right, everything, but HARC32 is 64bits.
This is why you cannot create an in-process session, since HAPI (and Houdini) are 64 bits only.

I've replied on your other topic, but linking to HARC32 on your 32 bits application, then connecting to an existing HARS process (x64) is the only solution to use Houdini Engine on x86.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB