GameMonkey Script

GameMonkey Script Forums
It is currently Mon Nov 20, 2017 3:39 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Dec 01, 2011 3:17 pm 
Offline

Joined: Fri Jun 19, 2009 12:39 pm
Posts: 31
I've run into some issues with the garbabe collection.

When the Garbage Collector runs, it seems to be trying to call my destruct call-back on the last allocated user object more than once, causing an exception. This only seems to be happening on objects that are allocated from inside of native functions.

I use the same method inside of my class for allocating the object from script or native code (see below).
Code:

static ScriptObject* Alloc(gmThread* a_thread)
{
   a_thread->GetMachine()->AdjustKnownMemoryUsed(sizeof(CLASS));
   ScriptObject* pObject = new CLASS;
   a_thread->PushNewUser(pObject, CLASS::getClassType()->getTypeId());

   pObject->onConstruct(a_thread);
   return pObject;
}

static s32 Alloc(gmThread* a_thread)
{
  Alloc(a_thread);
  return GM_OK;
}



Does anybody have any ideas on what I might be doing wrong?


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 01, 2011 3:47 pm 
Offline

Joined: Fri Jun 19, 2009 12:39 pm
Posts: 31
Update: it seems to be related to an issue when using a user type operator where destination and one of the sources is the same variable. For example, if I have the following;

Code:
a = sVec3("0 0 0");
b = sVec3("0 1 2");
a = a + b;


or

Code:
c = a + b;


I get the issue happening. The operator doesn't do anything all that fancy...just gets the two user objects, creates a new user object for operator[0], performs the add and that's it.


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 01, 2011 11:54 pm 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 698
That should not happen. GM's Destruct is actually a Finalize, supposed to be called once when the GC collects the discarded object.

I would like to know what the call stack looks like for both destruct calls. I'd like to confirm that it is the same object being destructed twice and not the same memory being recycled. I will try to reproduce this if I can.

Is your GC configured differently from default settings?


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 02, 2011 9:07 am 
Offline

Joined: Fri Jun 19, 2009 12:39 pm
Posts: 31
The GC configuration hasn't been changed.

I suspect that the problem is with how I create the return object for my operator. When it's created, my allocator/script contructor pushes a new user object, which I think is incorrect. It's resulting in two variables referencing the same user object.

I'll give it a go at some point today and let you know what I find.


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 05, 2011 12:00 pm 
Offline

Joined: Fri Jun 19, 2009 12:39 pm
Posts: 31
I had a little bit of time over the weekend to look into this, and it was as I thought. I was calling PushUser() for an object that was returned by an operator which caused the issue.


Top
 Profile  
Reply with quote  
PostPosted: Tue Dec 06, 2011 12:37 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 698
BinaryDad wrote:
I had a little bit of time over the weekend to look into this, and it was as I thought. I was calling PushUser() for an object that was returned by an operator which caused the issue.

That makes sense. You should have SetUser() on operand[0], not push the result. Glad you've solved it.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group