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

Recommended Posts

Greetings!
Im new to angelscript and honestly didnt program in C++ for a while so please be gentle to me ;)

I had no problems getting angelscript integrated in my IDE and stuff, but when i tried around with the ScriptEngine a bit i got a nasty error i cant solve.

My specs are:
Microsoft Visual Studio 2010
Windows 7 (64 bit)
Angelscript 22202

I use Angelscript as a static lib.

The code which does problems is this one ( Broke it down to be shorter. )
 [...] ScriptManager::ScriptManager(void) { // Create the script engine asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); int r = engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL); // get the main module ( Or create it...) main_module=engine->GetModule("main", asGM_ALWAYS_CREATE); // Register the standard string for use in AngelScript RegisterStdString(engine); // Ready. } ScriptManager::ScriptManager(std::string name, std::string path, bool dump) { // First set up the general stuff we need. ScriptManager(); // Load the designated file. std::string script=LoadScriptFile(path); main_module->AddScriptSection(name.c_str(), script.c_str()); // PROBLEMS HERE }

The last bit of code (namely: main_module->AddScriptSection(name.c_str(), script.c_str()); ) breaks my application. Visual Studio catchs the Exception. Edit: The messageCallback gives no output.

The debugger tells me that i got memory violation. __vfptr cant be interpreted as it seems.

I would be very gratefull if anyone knew an answer since im pretty much in to learn the AngelScript Scriptengine and language since it seems to fit my needs pretty well.

Share on other sites
This line:
 ScriptManager(); 
Doesn't do what you probably think it does. It default creates a temporary ScriptManager object; it doesn't call the constructor as part of the constructor it's called in.

Share on other sites
This would indeed explain much.
I guess thats it. Thanks a lot.

With warm regards, Kuro

Share on other sites
The proper way to call the default constructor is by the initialization list, like this:

 ScriptManager::ScriptManager(std::string name, std::string path, bool dump) : ScriptManager() { // Load the designated file. std::string script=LoadScriptFile(path); main_module->AddScriptSection(name.c_str(), script.c_str()); } 

This is new for C++11, so if you use this your code will not be compatible with slightly older compilers.

Regards,
Andreas

Share on other sites
I simply outsourced it to a private member function which initializes the stuff which i call from both constructors.
It simplifies reinitializing, so at some point i would have done so anyway, i guess.

Regardless, thanks a lot. I programmed in Java for the last three years, things are not as complicated as in C++ there. Before that i developed in C++ quite a lot but i got rusty in those years of simpleness.