Jump to content
  • Advertisement
Sign in to follow this  
Braden M

Problem with POD class ref array on AngelScript 2.25.2

This topic is 2200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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>
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 ); }
Edited by Braden M

Share this post

Link to post
Share on other sites
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... Edited by Braden M

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!