| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System;
- using System.Runtime.CompilerServices;
- namespace BansheeEngine
- {
- /// <summary>
- /// A base class for all script objects that interface with the native code.
- /// </summary>
- public class ScriptObject
- {
- /// <summary>
- /// A pointer to the native script interop object.
- /// </summary>
- internal IntPtr mCachedPtr;
- /// <summary>
- /// Notifies the native script interop object that the managed instance was finalized.
- /// </summary>
- ~ScriptObject()
- {
- if (mCachedPtr == IntPtr.Zero)
- {
- Debug.LogError("Script object is being finalized but doesn't have a pointer to its interop object. Type: " + GetType());
- #if DEBUG
- // This will cause a crash, so we ignore it in release mode hoping all it causes is a memory leak.
- Internal_ManagedInstanceDeleted(mCachedPtr);
- #endif
- }
- else
- Internal_ManagedInstanceDeleted(mCachedPtr);
- }
- /// <summary>
- /// Returns a pointer to the native script interop object.
- /// </summary>
- /// <returns>Pointer to the native script interop object</returns>
- internal IntPtr GetCachedPtr()
- {
- return mCachedPtr;
- }
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_ManagedInstanceDeleted(IntPtr nativeInstance);
- }
- }
|