Advertisement

In `weakref`, copying may not work as intended.

Started by April 04, 2018 12:39 AM
2 comments, last by WitchLord 6 years, 7 months ago

// `0x123` means the address of the object.

weakref<X> active(0x123);
free(0x123);     // cache.push_back(0x123)  And weakflag.Set(true)
0x123 = alloc(); // 0x123 = cache.pop_back()
weakref<X> tmp(0x123);

active = tmp; // Assignment is not executed because it is the following code

// weakref.cpp: ::operator =(const CScriptWeakRef &other)
//     // Don't do anything if it is the same reference
//     if( m_ref == other.m_ref )
//       return *this;

if( active.get() is null ) {
  println("is null!!!!");
}

I believe you're correct in your observation. The fact that the address is the same doesn't necessarily mean that it is the same object instance. Especially for the weakref that doesn't force the first object instance to stay alive.

I'll have it fixed.

Thanks for reporting it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

I've fixed this in revision 2483.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement