Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity removal crash fix Release #586

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion api/AltV.Net.Async/Elements/Entities/AsyncBaseObject.cs
Expand Up @@ -11,7 +11,7 @@ namespace AltV.Net.Async.Elements.Entities
{
[SuppressMessage("ReSharper",
"InconsistentlySynchronizedField")] // we sometimes use object in lock and sometimes not
public class AsyncBaseObject<TBase> : IBaseObject where TBase : class, IBaseObject
public class AsyncBaseObject<TBase> : IBaseObject, IInternalBaseObject where TBase : class, IBaseObject
{
public IntPtr NativePointer => BaseObject.NativePointer;
public IntPtr BaseObjectNativePointer => BaseObject.BaseObjectNativePointer;
Expand All @@ -28,6 +28,15 @@ public bool Exists
return BaseObject.Exists;
}
}

set
{
lock (BaseObject)
{
if (BaseObject is IInternalBaseObject internalBaseObject)
internalBaseObject.Exists = value;
}
}
}

public BaseObjectType Type => BaseObject.Type;
Expand Down Expand Up @@ -203,5 +212,10 @@ public bool RemoveRef()
{
return BaseObject.RemoveRef();
}

public void Remove()
{
AsyncContext.RunOnMainThreadBlockingNullable(() => BaseObject.Remove());
}
}
}
5 changes: 0 additions & 5 deletions api/AltV.Net.Async/Elements/Entities/AsyncBlip.cs
Expand Up @@ -641,10 +641,5 @@ public void Fade(uint opacity, uint duration)
BaseObject.Fade(opacity, duration);
}
}

public void Remove()
{
AsyncContext.RunOnMainThreadBlockingNullable(() => BaseObject.Remove());
}
}
}
5 changes: 0 additions & 5 deletions api/AltV.Net.Async/Elements/Entities/AsyncColShape.cs
Expand Up @@ -89,10 +89,5 @@ public bool IsVehicleIn(IVehicle entity)
return BaseObject.IsVehicleIn(entity);
}
}

public void Remove()
{
AsyncContext.RunOnMainThreadBlockingNullable(() => BaseObject.Remove());
}
}
}
5 changes: 0 additions & 5 deletions api/AltV.Net.Async/Elements/Entities/AsyncVehicle.cs
Expand Up @@ -1331,11 +1331,6 @@ public string ScriptData
}
}

public void Remove()
{
AsyncContext.RunOnMainThreadBlockingNullable(() => BaseObject.Remove());
}

public void Repair()
{
lock (BaseObject)
Expand Down
5 changes: 0 additions & 5 deletions api/AltV.Net.Async/Elements/Entities/AsyncVoiceChannel.cs
Expand Up @@ -93,10 +93,5 @@ public bool IsPlayerMuted(IPlayer player)
return BaseObject.IsPlayerMuted(player);
}
}

public void Remove()
{
AsyncContext.RunOnMainThreadBlockingNullable(() => BaseObject.Remove());
}
}
}
9 changes: 0 additions & 9 deletions api/AltV.Net.Client/Elements/Entities/BaseObject.cs
Expand Up @@ -28,15 +28,6 @@ public BaseObject(ICore core, IntPtr baseObjectPointer, BaseObjectType type)
exists = true;
}

public void Remove()
{
if (!Exists) return;
unsafe
{
Core.Library.Shared.Core_DestroyBaseObject(Core.NativePointer, this.BaseObjectNativePointer);
}
}

public override void CheckIfEntityExists()
{
CheckIfCallIsValid();
Expand Down
6 changes: 6 additions & 0 deletions api/AltV.Net.Shared/Elements/Entities/ISharedBaseObject.cs
Expand Up @@ -118,5 +118,11 @@ public interface ISharedBaseObject : IRefCountable
void OnRemove();

void CheckIfEntityExists();


/// <summary>
/// Removes the baseobject
/// </summary>
void Remove();
}
}
9 changes: 9 additions & 0 deletions api/AltV.Net.Shared/Elements/Entities/SharedBaseObject.cs
Expand Up @@ -280,5 +280,14 @@ public override int GetHashCode()
{
return NativePointer.GetHashCode();
}

public void Remove()
{
if (!exists) return;
unsafe
{
Core.Library.Shared.Core_DestroyBaseObject(Core.NativePointer, BaseObjectNativePointer);
}
}
}
}
12 changes: 4 additions & 8 deletions api/AltV.Net/Alt.Entity.cs
Expand Up @@ -4,16 +4,12 @@ namespace AltV.Net
{
public static partial class Alt
{
public static void RemoveVehicle(IVehicle vehicle) =>
Core.RemoveVehicle(vehicle);
public static void RemoveVehicle(IVehicle vehicle) => vehicle.Remove();

public static void RemoveBlip(IBlip blip) =>
Core.RemoveBlip(blip);
public static void RemoveBlip(IBlip blip) => blip.Remove();

public static void RemoveCheckpoint(ICheckpoint checkpoint) =>
Core.RemoveCheckpoint(checkpoint);
public static void RemoveCheckpoint(ICheckpoint checkpoint) => checkpoint.Remove();

public static void RemoveColShape(IColShape colShape) =>
Core.RemoveColShape(colShape);
public static void RemoveColShape(IColShape colShape) => colShape.Remove();
}
}
5 changes: 0 additions & 5 deletions api/AltV.Net/Elements/Entities/Blip.cs
Expand Up @@ -696,10 +696,5 @@ public void Fade(uint opacity, uint duration)
Core.Library.Shared.Blip_Fade(BlipNativePointer, opacity, duration);
}
}

public void Remove()
{
Alt.RemoveBlip(this);
}
}
}
5 changes: 0 additions & 5 deletions api/AltV.Net/Elements/Entities/Checkpoint.cs
Expand Up @@ -128,10 +128,5 @@ public Checkpoint(ICore core, IntPtr nativePointer) : base(core, GetColShapePoin
{
CheckpointNativePointer = nativePointer;
}

public void Remove()
{
Alt.RemoveCheckpoint(this);
}
}
}
5 changes: 0 additions & 5 deletions api/AltV.Net/Elements/Entities/ColShape.cs
Expand Up @@ -98,10 +98,5 @@ public bool IsVehicleIn(IVehicle vehicle)
Alt.LogWarning("colShape.IsVehicleIn is deprecated, use colShape.IsEntityIn instead");
return IsEntityIn(vehicle);
}

public virtual void Remove()
{
Alt.RemoveColShape(this);
}
}
}
5 changes: 0 additions & 5 deletions api/AltV.Net/Elements/Entities/Vehicle.cs
Expand Up @@ -1806,10 +1806,5 @@ public IVehicle TrainLinkedToForward
}
}
}

public void Remove()
{
Alt.RemoveVehicle(this);
}
}
}
5 changes: 0 additions & 5 deletions api/AltV.Net/Elements/Entities/VoiceChannel.cs
Expand Up @@ -97,10 +97,5 @@ public VoiceChannel(ICore core, IntPtr nativePointer) : base(core, GetBaseObject
{
VoiceChannelNativePointer = nativePointer;
}

public void Remove()
{
Alt.RemoveVoiceChannel(this);
}
}
}