SDK KB : How to use Shader InitUI2 within Shader Execute


Applies to: XSI 6.5 CgFx nodes with textures

If you look at the implementation of CgFX.cpp in the XSISDK folder you see that the CgFX_InitUI2() is called with the !pInstanceData->m_LayoutInitialized. This must always evaluate to false when called from Execute() otherwise you risk invalidating the in_pParams (ShaderPPG). Typically you get a crash in CgFX_BindParameters because the texture information in the ShaderPPG argument has been invalidated.

Change your code in Shader_Execute code to:

   Shader_InitUI2(in_pSysParams, in_pParams, io_pShaderInstanceData, false);

There are conditions where the InitUI2 method is called with AllowCreateParam=true but they are outside the context of the Execute() method; usually when you hit the reload button causing the PPG to refresh.

Also, if your shader defines texture samplers and you load fine but the textures are black it is because the Shader_InitUI2() method has not been called to define them. The post-load code calls the Shader_Init() method but not the Shader_InitUI2() method, this means that the samplers will not get initialized. To resolve the problem you need to manually reload the Fx from the PPG or change one of your parameters identified by Shader_GetRequirements RTS_REQUIRE_PRIMARYINITUIGUID or RTS_REQUIRE_SECONDARYINITUIGUID. This could be done in a self-installing plugin defining an OnEndLoad event.

This page was last modified 11:01, 10 Jun 2008.
This page has been accessed 1721 times.

© Copyright 2009 Autodesk Inc. All Rights Reserved. Privacy Policy | Legal Notices and Trademarks | Report Piracy