ScriptObject.cs 957 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. public class ScriptObject
  6. {
  7. internal IntPtr mCachedPtr;
  8. ~ScriptObject()
  9. {
  10. if (mCachedPtr == IntPtr.Zero)
  11. {
  12. Debug.LogError("Script object is being finalized but doesn't have a pointer to its interop object. Type: " + GetType());
  13. #if DEBUG
  14. // This will cause a crash, so we ignore it in release mode hoping all it causes is a memory leak.
  15. Internal_ManagedInstanceDeleted(mCachedPtr);
  16. #endif
  17. }
  18. else
  19. Internal_ManagedInstanceDeleted(mCachedPtr);
  20. }
  21. internal IntPtr GetCachedPtr()
  22. {
  23. return mCachedPtr;
  24. }
  25. [MethodImpl(MethodImplOptions.InternalCall)]
  26. private static extern void Internal_ManagedInstanceDeleted(IntPtr nativeInstance);
  27. }
  28. }