Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


#ActualWracky

Posted 03 October 2013 - 02:41 PM

Hi Andreas,

So I finally got around to implementing this, and I noticed a problem with the CScriptWeakRef.

The code you showed me for weakreffing the object in the engine throws an exception when I pass it a script object.

void FuncReceivingDelegate(asIScriptFunction *delegate)
{
   // Get the object pointer from the delegate
   if( delegate->GetFuncType() == asFUNC_DELEGATE )
   {
     void *obj = delegate->GetDelegateObject();
     asIObjectType *objType = delegate->GetDelegateObjectType();
     asIScriptFunction *method = delegate->GetDelegateFunction();
  
     // Create a weak ref to keep the pointer to the object
     CScriptWeakRef *weakRefToDelegatedObject = new CScriptWeakRef(obj, objType);
     
     // Store the weak ref and the method instead of the original delegate
     ...
   }
 
   delegate->Release();
}
The constructor for the CScriptWeakRef throws an exception on this line:
 
// Release the handle that was received, since the weakref isn't suppose to prevent the object from being destroyed
m_type->GetEngine()->ReleaseScriptObject(m_ref, m_type->GetSubType());

As far as I can see, GetSubType returns 0 if the object is not templated?
So it passes 0 as subtype here, and crashes in "ReleaseScriptObject" upon trying to access this null-pointer.

 

I've tried passing m_type instead of subtype when subtype was null, but that messes up the ref-count and destroys my object when it is still in scope.

adding another m_type->AddRef() didn't solve that.

Since I don't know exactly what I'm doing, I thought I'd ask ;-)

 

Here's my script:

Timer@ timer;

class Foo
{
  void bar()
  {
   	echo ("Called bar...\n");
  }
	
  ~Foo()
  {
  	echo ("Foo destroyed\n");
  }
}

Foo@ f;

void main(Control@ control)
{
  @f = Foo();
  @timer = control.createTimer(1000, true);
  timer.elapsed += Action(f.bar);
  timer.start();
}

Sincerely,

 

Wracky

 


#1Wracky

Posted 03 October 2013 - 02:33 PM

Hi Andreas,

So I finally got around to implementing this, and I noticed a problem with the CScriptWeakRef.

The code you showed me for weakreffing the object in the engine throws an exception when I pass it a script class.

void FuncReceivingDelegate(asIScriptFunction *delegate)
{
   // Get the object pointer from the delegate
   if( delegate->GetFuncType() == asFUNC_DELEGATE )
   {
     void *obj = delegate->GetDelegateObject();
     asIObjectType *objType = delegate->GetDelegateObjectType();
     asIScriptFunction *method = delegate->GetDelegateFunction();
  
     // Create a weak ref to keep the pointer to the object
     CScriptWeakRef *weakRefToDelegatedObject = new CScriptWeakRef(obj, objType);
     
     // Store the weak ref and the method instead of the original delegate
     ...
   }
 
   delegate->Release();
}
The constructor for the CScriptWeakRef throws an exception on this line:
 
// Release the handle that was received, since the weakref isn't suppose to prevent the object from being destroyed
m_type->GetEngine()->ReleaseScriptObject(m_ref, m_type->GetSubType());

As far as I can see, GetSubType returns 0 if the object is not templated?
So it passes 0 as subtype here, and crashes in "ReleaseScriptObject" upon trying to access this null-pointer.

 

I've tried passing m_type instead of subtype when subtype was null, but that messes up the ref-count and destroys my object when it is still in scope.

adding another m_type->AddRef() didn't solve that.

Since I don't know exactly what I'm doing, I thought I'd ask ;-)

 

Here's my script:

Timer@ timer;

class Foo
{
  void bar()
  {
   	echo ("Called bar...\n");
  }
	
  ~Foo()
  {
  	echo ("Foo destroyed\n");
  }
}

Foo@ f;

void main(Control@ control)
{
  @f = Foo();
  @timer = control.createTimer(1000, true);
  timer.elapsed += Action(f.bar);
  timer.start();
}

Sincerely,

 

Wracky

 


PARTNERS