Reading bytecode fails when combining namespace and shared class.

Started by
2 comments, last by WitchLord 5 years, 10 months ago

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

		mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
		mod->AddScriptSection("test",
"namespace X {"
"shared class A"
"{"
"  A()"
"    {}"
"}};"
      );
		r = mod->Build();
		if (r < 0)
			TEST_FAILED;

		asIScriptModule *mod2 = engine->GetModule("test2", asGM_ALWAYS_CREATE);
		mod2->AddScriptSection("test",
"namespace X {"
"external shared class A;"
"}"
"namespace Y {"
"class Test : X::A"
"{"
"  Test() {}"
"}};"
      );
		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;

#if 0
		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;
#else
        mod2->Discard();

        // game loop
        for(unsigned i = 0; i < 10; ++i) { 
          engine->GarbageCollect(); // run DeleteDiscardedModules();
        }
#endif

		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 the above is executed, the following error is output.


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

In the above example, while sharing module resides, we test that one module is recompiled into bytecode and from then on it is read.
By the way, you can read it normally after calling ShutDownAndRelease.

 

Advertisement

Thanks once more for the very detailed report with code to reproduce the problem.

I'll look into this 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 2505.

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