Re: [C++] Storing the new RendererContext object globally...

Date : Sun, 18 Mar 2007 15:31:31 -0700
To : XSI(at)Softimage.COM
From : "Steven Caron" <carons(at)gmail.com>
Subject : Re: [C++] Storing the new RendererContext object globally...
Thank you Wessam for your excellent response!

I have successfully compiled the project without linking errors, and I have full access to the context object outside the scope of the _process function.

Steven

On 3/18/07, Wessam Bahnassi <wbahnassi(at)inframez.com> wrote:

An extern variable in C++ has to have the following setup:

-          A declaration that will be visible to any module that wants to access that variable. This comes in the form:
extern int g_iMyExternVariable; // Note that you cannot initialize the extern's value here

-          The definition that describes which module will actually hold the data for the real object. This has to be local for a single CPP file only, as you only want to create a single object. This comes in the form:
int g_iMyExternVariable = 24; // Here you actually allocate the data and initialize it to some value.

 

In your case, you have the first requirement met in the cornwall.h header. However, the second one is missing, and that's why the linker is telling you it can't find the actual definition of the variable. Adding this line at the top of cornwall.cpp solves the issue:

RendererContext myRendererContext;

 

Now, one more note, a RendererContext object is actually of type CRef, so in order to fill it with the proper reference to the renderer context, you just do:

myRendererContext = in_ctxt;

instead of:

RendererContext myRendererContext(in_ctxt);

(which was only declaring a local variable in the scope of the containing function).

 

 

Wessam Bahnassi

Microsoft DirectX MVP,

Programmer

Electronic Arts

--

'Talk is cheap because supply exceeds demand'

 

From: owner-xsi(at)Softimage.COM [mailto: owner-xsi(at)Softimage.COM] On Behalf Of Steven Caron
Sent: Saturday, March 17, 2007 9:06 PM
To: xsi(at)Softimage.COM
Subject: [C++] Storing the new RendererContext object globally...

 

So I am playing with the new Renderer API and am having trouble storing the RendererContext globally and accessing it in another .cpp file. I first declare this variable in an .h file to be included in other .cpp files. In one of the required callbacks I attempt to define this variable by passing it the context object that is being passed into the callback. I then attempt to use that variable in my other .cpp file. What I end up getting is external linking errors. I have attached my project and am hoping someone could look at the code and share some insight as to why I can't get this to work. I have a feeling it is a problem with my understanding of the 'extern' keyword, I am probably not using it correctly hence my linking errors.

Thanks
Steven



Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.