Skip to main content
GameDev.net gamedev.net
🔒 Locked

Strange behavior when registering method with template specialization types

Started by ciccio3 Sep 3, 2022 at 2:32 PM 2 replies 7.6k views
Original Post
ciccio3
ciccio3

I stumbled upon an issue which looks like related to some internal state of the engine, basically I have a template type which is then specialized for some types:

registerType("Slice<class T>", sizeof(void*), asOBJ_VALUE | asOBJ_TEMPLATE, "a view to a native array");
check(engine->RegisterObjectBehaviour("Slice<T>", asBEHAVE_CONSTRUCT, "void _(int& in)", CALL_FUNCTION_OBJ_FIRST(slice_constructor), CDeclCallObjFirst));
check(engine->RegisterObjectBehaviour("Slice<T>", asBEHAVE_DESTRUCT, "void _()", CALL_FUNCTION_OBJ_FIRST(slice_destructor), CDeclCallObjFirst));
     
registerSliceSpecialization<ItemStack>("item::Stack", "a view to a sequence of item stacks");

Some are my helper methods which are used to slim down the boilerplate code.

Then I'm using Slice<item::Stack> :

registerMethodImpl("RecipeStep", "Slice<item::Stack> output()", CALL_FUNCTION_OBJ_FIRST(data::recipe::step_output), CDeclCallObjFirst, "");
registerMethodImpl("RecipeStep", "Slice<item::Stack> input()", CALL_FUNCTION_OBJ_FIRST(data::recipe::step_input), CDeclCallObjFirst, "");

Now, as long as both of these lines are uncommented I get the following error on the second line:

Error : Type 'Slice' is not a template type
Error : Failed in call to function 'RegisterObjectMethod' with 'RecipeStep' and 'Slice<item::Stack> input()' (Code: asINVALID_DECLARATION, -10)
AngelScript error: Error while registering method for RecipeStep: Slice<item::Stack> input()

but if I comment one of the two lines then the other method is successfully registered and it's working fine. It looks like related to some engine internal state which breaks after first registration but it's really unclear what's the problem.

WitchLord
WitchLord

Thanks for letting me know. I'll investigate this as soon as I can.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
WitchLord
WitchLord

Sorry for taking so long to look into this.

Unfortunately I've not been able to reproduce the problem you mentioned. I tried with the following piece of code, but it is registering fine without any errors reported. Can you help me figure out how to reproduce the issue by pointing out what is different from your code?

		asIScriptEngine* engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
		engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
		bout.buffer = "";

		r = engine->RegisterObjectType("Slice<class T>", sizeof(void*), asOBJ_VALUE | asOBJ_TEMPLATE); if (r < 0) TEST_FAILED;
		r = engine->RegisterObjectBehaviour("Slice<T>", asBEHAVE_CONSTRUCT, "void _(int& in)", asFUNCTION(0), asCALL_GENERIC); if (r < 0) TEST_FAILED;
		r = engine->RegisterObjectBehaviour("Slice<T>", asBEHAVE_DESTRUCT, "void _()", asFUNCTION(0), asCALL_GENERIC); if (r < 0) TEST_FAILED;

		r = engine->SetDefaultNamespace("item"); if (r < 0) TEST_FAILED;
		r = engine->RegisterObjectType("Stack", sizeof(int), asOBJ_VALUE | asOBJ_POD); if (r < 0) TEST_FAILED;
		r = engine->SetDefaultNamespace(""); if (r < 0) TEST_FAILED;

		r = engine->RegisterObjectType("Slice<item::Stack>", sizeof(void*), asOBJ_VALUE); if (r < 0) TEST_FAILED;
		r = engine->RegisterObjectBehaviour("Slice<item::Stack>", asBEHAVE_CONSTRUCT, "void _(int& in)", asFUNCTION(0), asCALL_GENERIC); if (r < 0) TEST_FAILED;
		r = engine->RegisterObjectBehaviour("Slice<item::Stack>", asBEHAVE_DESTRUCT, "void _()", asFUNCTION(0), asCALL_GENERIC); if (r < 0) TEST_FAILED;

		r = engine->RegisterObjectType("RecipeStep", sizeof(void*), asOBJ_VALUE | asOBJ_POD); if (r < 0) TEST_FAILED;
		r = engine->RegisterObjectMethod("RecipeStep", "Slice<item::Stack> output()", asFUNCTION(0), asCALL_GENERIC); if (r < 0) TEST_FAILED;
		r = engine->RegisterObjectMethod("RecipeStep", "Slice<item::Stack> input()", asFUNCTION(0), asCALL_GENERIC); if (r < 0) TEST_FAILED;

		if (bout.buffer != "")
		{
			PRINTF("%s", bout.buffer.c_str());
			TEST_FAILED;
		}

		engine->ShutDownAndRelease();
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.