🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

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

Started by
2 comments, last by WitchLord 6 years, 2 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!!!!");
}

Advertisement

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

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