SetName leads to Access Violation
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/02/2010 at 10:34, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 11.5
Platform: Windows ;
Language(s) : C++ ;---------
Hello,
I have written an import filter to import a custom file format for mass information. The file contains names of Scenes to merge into the current document and it then sets animation keys for them and renames them. The plugin was working fine with 9.52 32bit.
I now installed the upgrade to 9.6 and tried porting to 64bit, which caused some trouble in getting Visual C++ Express Edition 2008 to produce x64 code, but finally succeeded and the plugin worked fine with 9.6 32bit(when compiled for 32bit), but caused a crash (access violation) in C4D 64bit when compiled for x64, at a SetName() statement.
Since I'm expecting the 11.5 upgrade to arrive this week, I decided not to bother with 9.6 and installed the 11.5 demo to try and get it to work there.
But no luck, after adopting everything that changed regarding AnimationTracks and getting it to compile, I still get Access Violations at the SetName statement.
Here is a code snippet:
LONG STLLoaderData::Load(PluginSceneLoader *node, const Filename &name, BaseDocument *doc, LONG flags, String *error, BaseThread *thread)
{
BaseContainer bc;
LONG i=0;
STLLOAD stl;
String fields[50];
LONG NF;
Vector v;
if (!stl.file) return FILEERROR_MEMORY;
if (!stl.file->Open(name,GE_READ,FILE_NODIALOG,GE_INTEL)) return stl.file->GetError();
stl.flags = flags;
stl.filelen = stl.file->GetLength();
GeConsoleOut(String("Starting Processing"));
while ((stl.filepos<stl.filelen && stl.ReadArg())) { //&&(i<500)) {
String currline(stl.str);
NF=0;
GeConsoleOut(String("Processing")+currline);
while (currline!="") {
LONG pos;
if (currline.FindFirst(";",&pos,0)) {
fields[NF++]=currline.SubStr(0,pos);
currline.Delete(0,pos+1);
} else {
fields[NF++]=currline;
currline="";
}
}
if (fields[0]=="MinFrame") {
GeConsoleOut(String("1a"));
doc->SetFps(25);
BaseTime t(fields[1].StringToReal());
doc->SetMinTime(t);
MinFrame=fields[1].StringToReal();
} else if (fields[0]=="MaxFrame") {
doc->SetFps(25);
BaseTime t(fields[1].StringToReal());
doc->SetMaxTime(t);
MaxFrame=fields[1].StringToReal();
} else if (fields[0]=="ObjectId") {
BaseObject *newobj;
MergeDocument(doc,Filename(fields[13]),flags,thread);
newobj=doc->SearchObject("Darwinian");
if (newobj==NULL) {
GeConsoleOut(String("I really need a Darwinian!!"));
return FILEERROR_WRONG_VALUE;
}
GeConsoleOut(String("Gonna set name'")+fields[1]+"'");
newobj->SetName(fields[1]); // <- here it fails
}
v.x=fields[2].StringToReal();
v.y=fields[3].StringToReal();
v.z=fields[4].StringToReal();
newobj->SetPos(v);
v.x=fields[5].StringToReal();
v.y=fields[6].StringToReal();
v.z=fields[7].StringToReal();
newobj->SetRot(v);The error message I get is:
Unhandled exception at 0x0000000140df3800 in CINEMA 4D Demo 64 Bit.exe: 0xC0000005: Access violation at location 0x0000000140df3800.
The "Gonna set name..." GeConsoleOut statement works as expected and prints out the name correctly, so the string seems to be ok (it contains "0000000Header").
Any ideas?
BTW, When I open the file to be imported, the console reads out "Checking type" twice, before my plugin is called. Any ideas what this means, or if it is relevant?
Thanks for helping
Mike -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/02/2010 at 10:47, xxxxxxxx wrote:
BTW, the exact point where it fails is (according to debugger) in c4d_baselist.h, line 464 at
void SetName(const String &name) { AtCall(SetName)(name); } -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/02/2010 at 14:07, xxxxxxxx wrote:
Not sure how you got the express version to compile for 64bit but actually it is not able to build valid 64bit executables. That may be the problem.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/02/2010 at 14:12, xxxxxxxx wrote:
Katachi,
I followed this guide: http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets/
I have this import plugin, and I have a tag. The tag is working in 64 bit.
Nevertheless, since Visual Studio 2005 appears to be the recommended version für Cinema 4D, I ordered one from eBay for 50EUR, which I consider a fair price (considering I will only use it for those few hundred lines of code). -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/02/2010 at 14:12, xxxxxxxx wrote:
ok forget about this. it seems with the newer express editions it works with the net framework installed.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/02/2010 at 14:18, xxxxxxxx wrote:
I may see a problem in your mergedocument call. You are passing the document pointer which you don´t have ownership of. The doc belongs to cinema 4d. The mergedocument call however requires a pointer to a document that you own. This may well lead to the crash later on. Just a guess at first sight.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/02/2010 at 14:27, xxxxxxxx wrote:
Hm but I cannot seem to find any alternate call that would allow me to merge the new data into the doc that my load call gets.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/02/2010 at 14:37, xxxxxxxx wrote:
For testing, I substituted the MergeDocument call for a LoadDocument, so that I own it; and I also tried a GetName() before the SetName:
doc=LoadDocument(Filename(fields[13]),flags,thread);
if (doc==NULL) {
GeConsoleOut(String("Failed to load document ")+fields[13]);
return FILEERROR_WRONG_VALUE;
}
newobj=doc->SearchObject("Darwinian");
if (newobj==NULL) {
GeConsoleOut(String("I really need a Darwinian!!"));
return FILEERROR_WRONG_VALUE;
}
GeConsoleOut(String("Got name '") + newobj->GetName() + "'");
It still fails, and it also fails in the GetName, not only in the SetName.
Might it have to do with the expected const-ness of the string? Wouldn't think so... -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 17/02/2010 at 00:30, xxxxxxxx wrote:
Does it still fail if you just pass a string instead of your array?
Something like this:
newobj->SetName("test");
Btw. please when posting code do it in a formated, readable form. I had to spend some minutes just to bring it into a readable shape. There are code tags for posting source code. Also try to remove any unnecessary parts of the code.
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 17/02/2010 at 02:25, xxxxxxxx wrote:
Hello Matthias,
thanks for pointing out the formatting options. Since I was not sure which part might be key to the problem I did not strip to much (I already stripped a few dozen GeConsoleOut's that I placed to check how far execution goes before the error occurs).
I can trynewobj->SetName("test");
in the evening. What I already tried (and what also didn't work) was
newobj->SetName(String("test"));
I did, however, try to uncomment the GetName() and SetName(), and then the SetPos() and SetRot() were working fine (it then failed later on in an ordinary fashion when it couldn't find the renamed Object, since there was no rename).
So, somehow it appears to be related to the String type, possibly in combination with the passing as a reference. Perhaps something in the implementation/binary representation of a String has changed in the Win7 SDK.
Or perhaps it has to do with some compiler settings on how to pass References to Strings.
Would be strange,though, as AFAIR I also have to pass references to strings during Registration of the Plugin.
Today, I received my package with R11.5 , but I decided to only install it after I also received Visual Studio 2005, so that I can make a full uninstall of Visual C++ Express Edition and Win7 SDK, so that I will start with a fresh build environment.
BTW, is it recommended to use Visual Studio 2005 "out of the box" or to use a certain SDK with it(when building for C4D R11.5)? -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 17/02/2010 at 02:35, xxxxxxxx wrote:
Originally posted by xxxxxxxx
BTW, is it recommended to use Visual Studio 2005 "out of the box" or to use a certain SDK with it(when building for C4D R11.5)?
Just use the standard installation, make sure to enable the x64 compiler options in the installer.
Download the the VS 2005 updates through Microsoft Update, especially if you are using Windows Vista or 7.
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/02/2010 at 19:28, xxxxxxxx wrote:
Hi,
I now installed VS 2005 and had the same problems.
Then I deleted all compiler settings, solution files etc., and used the cinema4dsdk settings as a template. That did the trick and now it works *phew*
Thanks fpr helping!