Skip to content

Commit

Permalink
Additional check for object copying
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Jun 10, 2023
1 parent 4d57686 commit 2eec57f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions CVRLua/Lua/LuaDefs/ObjectDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int Destroy(IntPtr p_state)
{
if(l_obj != null)
{
if(l_obj.IsSafeToDestroy())
if(l_obj.IsSafeToManipulate())
{
UnityEngine.Object.Destroy(l_obj);
l_argReader.PushBoolean(true);
Expand Down Expand Up @@ -98,8 +98,16 @@ static int Instantiate(IntPtr p_state)
{
if(l_obj != null)
{
UnityEngine.Object l_copy = UnityEngine.Object.Instantiate(l_obj);
l_argReader.PushObject(l_copy);
if(l_obj.IsSafeToManipulate())
{
UnityEngine.Object l_copy = UnityEngine.Object.Instantiate(l_obj);
l_argReader.PushObject(l_copy);
}
else
{
l_argReader.SetError("Attempt to instantiate unsafe Object");
l_argReader.PushBoolean(false);
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion CVRLua/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace CVRLua
{
public class Core : MelonLoader.MelonMod
{
public const int c_modRelease = 25;
public const int c_modRelease = 26;

static public Core Instance { get; private set; } = null;

Expand Down
2 changes: 1 addition & 1 deletion CVRLua/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void MergeInto<T>(this List<T> p_source, List<T> p_target)
p_source.ForEach(p => p_target.Add(p));
}

public static bool IsSafeToDestroy(this UnityEngine.Object p_object)
public static bool IsSafeToManipulate(this UnityEngine.Object p_object)
{
GameObject l_rootObject = null;
if(p_object is Component)
Expand Down

0 comments on commit 2eec57f

Please sign in to comment.