Problem with POD class ref array on AngelScript 2.25.2

Started by
0 comments, last by Braden M 11 years, 4 months ago
Never mind ... I solved this right after posting wacko.png

I'm not sure if I'm [ab]using AngelScript incorrectly, or if the garbage collector has a bug, but with the following testcase, I am unable to destroy a dynamic configuration group under certain conditions, involving mentions in the code of an array of refs to C++ POD struct objects.

The code is below, and the exception asCONFIG_GROUP_IS_IN_USE/"Unable to remove the dynamic configuration group." is getting thrown at the very end. Note that I'm not actually running any code; just building it. It seems that the engine is not freeing the "NotFreed" class type correctly. But maybe I'm doing something wrong? Any help would be appreciated.


#include <angelscript.h>
#include <angelscript/add_on/scriptstdstring.h>
#include <angelscript/add_on/scriptarray.h>
#define SCRIPT_SOURCE_INLINE(a) #a
int main() {

asIScriptEngine* p_engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
int r = p_engine->SetMessageCallback(asFUNCTION(&YourPreferredASCallback), 0, asCALL_CDECL); assert( r >= 0 );

RegisterStdString(p_engine); // Use STL strings as our string type
RegisterScriptArray(p_engine, false); // Enable support for arrays
// The problematic struct
struct DoublePair { double a, b; };

r = p_engine->BeginConfigGroup("exampleGroup"); assert( r >= 0);
r = p_engine->RegisterObjectType("DoublePair", sizeof(DoublePair), asOBJ_VALUE|asOBJ_APP_CLASS|asOBJ_POD); assert(r >= 0); // |asOBJ_APP_CLASS_ALLFLOATS ?
asIScriptModule* p_module = p_engine->GetModule("gcErrorExample", asGM_ALWAYS_CREATE);
p_module->AddScriptSection("example", SCRIPT_SOURCE_INLINE(
class NotFreed {
string name;
NotFreed( DoublePair test ) { }
}
class OtherClass {
OtherClass() {}
array<NotFreed@> my_array;
void SomeMethod() {
for (uint i=0;i<my_array.length();i++) {
// If the following line is commented out, everything works fine.
my_array.name = "test";
}
}
// Another way to trigger the error: (uncomment the next line)
//void OtherMethod(array<NotFreed@> arg) {}
}
));
r = p_module->Build(); assert(r >= 0);
r = p_engine->GarbageCollect(); assert( r >= 0);
r = p_engine->DiscardModule("gcErrorExample"); assert( r >= 0);
r = p_engine->RemoveConfigGroup("exampleGroup");
if (r == asCONFIG_GROUP_IS_IN_USE) {
throw std::runtime_error("Unable to remove the dynamic configuration group."); // This gets thrown
} else { assert( r >= 0 ); }
p_engine->Release();
}
Advertisement
Wow, never mind. Solved my own problem just after I posted! I had to swap GarbageCollect() and DiscardModule() at the end, and now it all works. I can't see how to delete this thread though...

This topic is closed to new replies.

Advertisement