Advertisement

AddScriptSection crashs

Started by March 12, 2012 01:07 PM
3 comments, last by KuroSei 12 years, 8 months ago
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. tongue.png )

[...]

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. smile.png

If you need more information i missed for some reason feel free to ask and i will answer asap.
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.
Advertisement
This would indeed explain much. :D
I guess thats it. Thanks a lot.

With warm regards, Kuro
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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.

This topic is closed to new replies.

Advertisement