{
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"
"{"
"}"
"shared class B : A"
"{"
" void bar() {}"
"}}"
);
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;"
"external shared class B;"
"}"
"namespace Y {"
"class Test : X::A"
"{"
" X::B b;"
" void foo() { b.bar(); }"
"}}"
);
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;
mod2->Discard();
// game loop
for (unsigned i = 0; i < 10; ++i) {
engine->GarbageCollect(); // run DeleteDiscardedModules();
}
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 you execute the above, the following will be output.
(0, 0) : Error : LoadByteCode failed. The bytecode is invalid. Number of bytes read from stream: 255
Similar to this case, it seems that problems will occur with virtual method restore this time.