🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Using lambda function in shared class fails to read bytecode

Started by
4 comments, last by WitchLord 6 years ago

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

		mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
		mod->AddScriptSection("test",
"shared funcdef void TestFunc();"
"shared class TestBase"
"{"
"  void callfn(TestFunc@ fn)"
"    {"
"    }"
"  void test()"
"    {"
"      callfn( function() { } );"
"    }      "
"};"
      );
		r = mod->Build();
		if (r < 0)
			TEST_FAILED;

		asIScriptModule *mod2 = engine->GetModule("test2", asGM_ALWAYS_CREATE);
		mod2->AddScriptSection("test",
"external shared funcdef void TestFunc();"
"external shared class TestBase;"
"class Test : TestBase"
"{"
"};"
      );
		r = mod2->Build();
		if (r < 0)
			TEST_FAILED;

		CBytecodeStream bc1("test");
		r = mod->SaveByteCode(&bc1); assert(r >= 0);
		if (r < 0)
			TEST_FAILED;

		CBytecodeStream bc2("test2");
		r = mod2->SaveByteCode(&bc2); assert(r >= 0);
		if (r < 0)
			TEST_FAILED;

		engine->ShutDownAndRelease();
		engine = asCreateScriptEngine();
		engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);

		mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
		r = mod->LoadByteCode(&bc1);
		if (r < 0)
			TEST_FAILED;

		mod2 = engine->GetModule("test2", asGM_ALWAYS_CREATE);
		r = mod2->LoadByteCode(&bc2);
		if (r < 0)
			TEST_FAILED;

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

		engine->ShutDownAndRelease();
	}

When preparing and executing the above code, it stops with the following error.
 


 (0, 0) : Error   : LoadByteCode failed. The bytecode is invalid. Number of bytes read from stream: 287

 

Advertisement

Thanks for the report. I'll have it fixed as soon as possible.

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've fixed this in revision 2506.

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

It seems that trouble occurs with the code which was originally working.
I have not examined it in detail, but if you make the following corrections, the problem will not occur.


				if (func2->funcType == asFUNC_VIRTUAL)
					func2 = ot->virtualFunctionTable[func2->vfTableIdx];

				if (func->IsSignatureEqual(func2))
				{
					func->DestroyHalfCreated();
					func = func2;

+                   savedFunctions[savedFunctions.GetLength()-1] = func2;

					// as this is an existing function it shouldn't be translated as if just loaded
					dontTranslate.Insert(func2, true);

I do not understand it much, I am not confident because it is a patch by intuition.

You're right. The savedFunctions array needed to be updated too just like you did. I didn't have multiple classes in my test case so I didn't detect this problem before, but now I've fixed this in revision 2507.

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