Thanks for the excellent tip!
As you suggest I've posted it to the wiki (and encourage you
to contribute there directly as much as you like!)
http://softimage.wiki.avid.com/index.php/Cpp_API_Overview_%28XSISDK%29#Strings
And the bad line from the dotXSIConverter code that you point out will be removed!
Also, while on the subject I'd like to point out this wiki page for people who haven't
seen it:
http://softimage.wiki.avid.com/index.php/Porting_Scripts_to_Cpp_%28XSISDK%29
-Andrew
-----Original Message-----
From: owner-3dgames(at)Softimage.COM [mailto:owner-3dgames(at)Softimage.COM]On
Behalf Of Wessam Bahnassi
Sent: Friday, March 24, 2006 7:18 AM
To: 3DGames(at)Softimage.COM
Subject: NEVER store string pointers in Cpp SDK
Hi all,
After spending a couple of days trying to pinpoint a damn memory corruption
bug in our XSI plug-in, I found that it's all caused by a casual use of
XSI::CString class...
Look at this code snip:
XSI::Parameter param; // Assume this is a valid XSI param object...
const char *pszString = param.GetName().GetAsciiString();
printf(pszString); // Potential crash!
What happens is that param.GetName() returns a temp XSI::CString object. And
after the call to GetAsciiString(), this temp string object is destroyed,
rendering the pointer pszString potentially invalid...
Of course in our code we do a lot more stuff instead of printf(), and that
put me in endless wonders why many of the strings I receive are garbage!
I hope this saves some poor souls out there as I don't like to see people
suffering from this mistake...
BTW, I found a similar line in the SDK sample dotXSIConverter, file
cnv_model.cpp:
const wchar_t *l_pName = l_XSIModel.GetName().GetWideString();
Fortunately the pointer returned isn't used anywhere, so no physical harm is
done :)
(perhaps this should be added to the Softimage wiki?)
Thanks,
Wessam Bahnassi
Microsoft DirectX MVP,
Lead Programmer
In|Framez
--
In|Structurez Arabic Gamedev Community
www.instructurez.com
---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe 3dgames
---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe 3dgames