Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

Problem with POD class ref array on AngelScript 2.25.2


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Braden M   Members   -  Reputation: 126

Like
0Likes
Like

Posted 07 December 2012 - 04:54 PM

Never mind ... I solved this right after posting Posted Image

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[i].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();
}

Edited by Braden M, 07 December 2012 - 05:00 PM.


Sponsor:

#2 Braden M   Members   -  Reputation: 126

Like
0Likes
Like

Posted 07 December 2012 - 04:59 PM

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, 07 December 2012 - 04:59 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS