Re: Strange behavior with global variables in XSI plugins (C++)

Date : Mon, 25 Jun 2007 17:54:45 +0200
To : XSI(at)Softimage.COM
From : "Christopher Crouzet" <christopher.crouzet(at)gmail.com>
Subject : Re: Strange behavior with global variables in XSI plugins (C++)
Hmmm... I feel terribly stupid, why didn't I think to this ? arghhhhhhh !!

It now works fine, thanks a lot Wessam.


When I did some tests, I remarked that, as you said, XSI load various times the plugin, and I already saw this type of behavior with some CustomProperty callbacks (the Define callback was called twice if my memory is correct).
Does anyone know how it really works ?

And I fill convinced that the previous code should work, what happened to the pointer ?


Christopher.



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

It seems that your DLL is being loaded/unloaded/reloaded various times (depends on how XSI decides to manage the plug-in). For that, you might want to try putting your single-time init stuff in NewCommand_Init instead. And probably then a global pointer to a dynamically allocated class might be better (just as you do with pfoo).

 

I hope this helps,

 

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 Christopher Crouzet
Sent: Monday, June 25, 2007 7:29 AM
To: XSI Mailing List
Subject: Strange behavior with global variables in XSI plugins (C++)

 

Hello,


I need to initialize some data when a plugin is loaded in order to retrieve the data whenever I want during the XSI session.
But it doesn't work as I would like to (using XSI v6.01).

The data is encapsulated in a class Foo.
I attached the source code with the mail.


Here are the outputs, first with the variable pfoo which points to the class Foo :

    ' INFO : pfoo #Constructor
    ' INFO : ------------------------------------------------------------
    ' INFO : XSILoadPlugin
    ' INFO : pfoo pointer address: 00034010
    ' INFO : pfoo class address: 0E1840B0
    ' INFO : pfoo->val: Hi!
    ' INFO : ------------------------------------------------------------

    All works fine for the moment.

    ' INFO : ------------------------------------------------------------
    ' INFO : NewCommand_Execute
    ' INFO : pfoo pointer address: 00034010
    ' INFO : pfoo class address: 00000000
    ' INFO : ------------------------------------------------------------

    The pointers now points to NULL, what happened ?




And now the outputs for the foo variable :

    ' INFO : foo #Constructor
    ' INFO : ------------------------------------------------------------
    ' INFO : XSILoadPlugin
    ' INFO : foo address: 016C4010
    ' INFO : foo.val: Hi!
    ' INFO : ------------------------------------------------------------
    ' INFO : foo #Destructor

    Why the destructor has been fired ?

    ' INFO : foo #Constructor
    ' INFO : ------------------------------------------------------------
    ' INFO : NewCommand_Execute
    ' INFO : foo address: 016C4010
    ' INFO : foo.val: val
    ' INFO : ------------------------------------------------------------

    Now the constructor is fired again and the foo.val value has been reinitialized.



One another 'funny' thing is that the pfoo pointer address is some time not the same in NewCommand_Execute as it is in the XSILoadPlugin callback.
So, what did I wrong ? Did I miss something ? Is it a bug ?

What can I do to store a global variable such this during all the life of a plugin ?


Thank you !
Christopher.



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.