• Advertisement
Sign in to follow this  

Assert on Parameters in constructor.

This topic is 4773 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a small small class that i would like to be able to pass a string reference object in as a parameter in the constructor of the object. The problem is that i get an assertion at this line: as_compiler.cpp line 229: // At this point there should be no variables allocated assert(variableAllocations.GetLength() == freeVariables.GetLength());

Share this post


Link to post
Share on other sites
Advertisement
This looks like a bug in the library.

Could you show me the script statement you use to create this object? And how you registered the constructor function?

What version of the library are you using? 2.1.0 WIP 6?

Share this post


Link to post
Share on other sites

r=engine->RegisterObjectBehaviour("File", asBEHAVE_CONSTRUCT, "void f(string &in)", asFUNCTION(FileInitConstructor), asCALL_CDECL_OBJLAST); assert(r >= 0);



The exception occures before the constructor is called, the script looks like this:


void main()
{
File f("c:/test.txt");
}



The constructor is basic:


static void FileInitConstructor(string &Path, ASFileIO *file)
{
new(file) ASFileIO(Path);
}

Share this post


Link to post
Share on other sites
Thanks. I'll try to fix this problem during the weekend (or earlier if possible).

The problem is in the compilation of the script, so the implementation of your constructor is not the cause of the problem. What I find the most strange is that I already have a test similar to this that works without problem.

From teststdstring.cpp:


engine->RegisterObjectType("obj", 4, asOBJ_PRIMITIVE);
engine->RegisterObjectBehaviour("obj", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Construct1), asCALL_CDECL_OBJLAST);
engine->RegisterObjectBehaviour("obj", asBEHAVE_CONSTRUCT, "void f(string &in)", asFUNCTION(Construct2), asCALL_CDECL_OBJLAST);
engine->RegisterObjectBehaviour("obj", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(Destruct), asCALL_CDECL_OBJLAST);

// Verify that it is possible to use the string in constructor parameters
engine->ExecuteString(0, "obj a; a = obj(\"test\")", &out);


It could be that you are declaring the variable with the constructor parameters directly, whereas in my test I instanciate the object constructor as a temporary variable. I'll verify this.

Regards,
Andreas

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement