Advertisement

crash after msgCallback

Started by February 25, 2009 02:02 PM
8 comments, last by WitchLord 15 years, 9 months ago
hi, sorry but i have looked through all information that i could find, but i have not found the error in my code that lets AS crash after calling the msgCallback function. i register it

result = engine->SetMessageCallback(asMETHOD(ScriptEngine,msgCallback), this, asCALL_THISCALL);
link to source and upon error it crashes after walking through the function itself:

void ScriptEngine::msgCallback(const asSMessageInfo *msg, void *param)
{
	// AFTER HERE: CRASH!
	// even if this whole method is empty ...
}
link to source do you spot any error? because i dont know why it crashes :( btw, the exception callbacks are also not working for some reason :( thank you, thomas
When you register a message callback that's a member function, you don't put in the void * second argument. Example:
class COutStream{public:	void Callback(asSMessageInfo *msg) 	{ 		const char *msgType = 0;		if( msg->type == 0 ) msgType = "Error  ";		if( msg->type == 1 ) msgType = "Warning";		if( msg->type == 2 ) msgType = "Info   ";		printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, msgType, msg->message);	}};// somewhere elseCOutStream out;engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);
Advertisement
thank you very much, worked perfectly! :)
Does this mean that Rigs of Rods is switching from Lua to AngelScript? ;)

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

Quote: Original post by WitchLord
Does this mean that Rigs of Rods is switching from Lua to AngelScript? ;)

yes, thats what it means :)

i have evaluated all the possible options that are available, and your engine looks like the best fit to the requirements we have :)

thanks for such a nice system!

just finished implementing an ingame angelscript console :)
there is still lots of work to be done:
- add interfaces to some basic Ogre Classes (Vector3, etc)
- add the scripting engine to the lowest gameplay features:
- all game behavior is going to be scripted (terrain loading, truck selection)
- integration of the network protocol with angelscript
- the script system should be able to support a complete mission features in singleplayer as well as interactive 'missions' in Multiplayer.

- must finish integration of AS with the rest of the system:
- Cache System
- Water and weather system
- traction system
...

so that are just some bullet points that came straight to my head. You see there is much work to be done.
Anyone who is able to is invited to work on that topic as well (since its open source now)
That's great to hear.

Let me know if there are any features you'd like me to add to AngelScript. Developement is continuous and depending on your wishes I'll do my best to accomodate them.

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

Advertisement
thanks for that :)

i am really new to AS, thus i still have problems with the most basic things currenty, i hope you dont mind if i ask questions from time to time :)

currently i have a problem to create the interface for one of my classes:
CacheSystem.h

i would like to be able to call nearly all functions from AS as well. So i started with adding the Cachesystem and one function:

	result = engine->RegisterObjectType("CacheSystemClass", sizeof(CacheSystem), asOBJ_REF);	result = engine->RegisterObjectMethod("CacheSystemClass", "string &stripUIDfromString(const string ∈)", asFUNCTION(stripUIDfromString), asCALL_CDECL_OBJLAST);	result = engine->RegisterObjectBehaviour("CacheSystemClass", asBEHAVE_ADDREF, "void f()",asMETHOD(CacheSystem,addRef), asCALL_THISCALL);	result = engine->RegisterObjectBehaviour("CacheSystemClass", asBEHAVE_RELEASE, "void f()",asMETHOD(CacheSystem,release), asCALL_THISCALL);


and i wrote a wrapper for the string result that this function returns:
CScriptString &stripUIDfromString(std::string str){	CScriptString *rstr = new CScriptString(CACHE.stripUIDfromString(str).c_str());	return *rstr;}


is it always required to write such a wrapper or could i somehow use the function directly (Ogre::String is in fact std::string)?

also, how do i prevent the AS from creating new instances of the class? it should just be able to communicate with my singleton created in c++.

thank you very much :)
Please don't hesitate to ask questions. I'm here to help.

Unfortunately if you use CScriptString, you can't register functions that return a std::string by reference directly. This is because the script may decide to store a handle to the CScriptString by calling AddRef, which would then corrupt the memory as it is not a true CScriptString.

You also need to write your wrapper function to return a handle to the CScriptString, rather than a reference. Otherwise you'll get a memory leak.

	result = engine->RegisterObjectMethod("CacheSystemClass", "string @stripUIDfromString(const string ∈)", asFUNCTION(stripUIDfromString), asCALL_CDECL_OBJLAST);CScriptString *stripUIDfromString(std::string str){	CScriptString *rstr = new CScriptString(CACHE.stripUIDfromString(str).c_str());	return rstr;}


If you'd like you could register the std::string directly as a value type with AngelScript. Then you would be able to register the functions that work with std::string directly, without any need for wrappers. I already have code for this in /tests/test_feature/source/stdstring.cpp.

Which string type that is best for your application depends a lot on how much the scripts use strings.



To prevent the scripts from instanciating objects of a specific type, you would register the type as a reference type, but omit the factory behaviours. (Manual: Registering an uninstanciable reference type) This makes it impossible for the script to create its own instances.

You may also want to register the type with asOBJ_NOHANDLE, which prevents the scripts from storing handles to the instance. (Manual: Registering a single-reference type) Then you'll provide access to the singleton by registering it as a global property.

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

thanks for the fast and long reply! :)
i replaced cstring with std::string, works perfectly!

also i tried to register a classes static function to a class object, which i could not achieve. So currently i have the static function hanging around in the global namespace instead under the class instance. Was it an error by me or is it a limitation?
The AngelScript language doesn't have the concept of static class methods, so when registering a C++ static method you have to register it as a global function instead.

I may eventually add support for static methods in the script language as well, but it is currently very low priority.

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

This topic is closed to new replies.

Advertisement