Closed Strichinger closed 10 years ago
Are you using Player.PutInVehicle? Can you provide an example that causes this crash?
Here is my class (uncommented, sorry :3)
using MyLife.WorldRelated.PlayerRelated;
using SampSharp.GameMode.Definitions;
using SampSharp.GameMode.SAMP;
using SampSharp.GameMode.World;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyLife.WorldRelated.VehicleRelated
{
public class TemporaryVehicle : Vehicle, IOwnable
{
private Player _Player;
#region Player
public Player Player
{
get
{
return _Player;
}
set
{
if (value != null && Player == null)
{
_Player = value;
if (this.Player.InAnyVehicle && !this.Player.IsInVehicle(this))
{
this.Player.RemoveFromVehicle();
}
this.Player.SendClientMessage(Color.Green, "Dieses temporäre Fahrzeug (" + this.Info.Name + ") verschwindet, sobald du aussteigst.");
this.SetParams(true, true, false, true, false, false, false);
if (!this.Player.IsInVehicle(this))
{
this.Player.PutInVehicle(this, 0); // <-- Server crashes here
}
CreateTimer();
}
}
}
#endregion
public TemporaryVehicle(int id)
: base(id)
{
this.SetNumberPlate("TEMP");
this.PlayerEnter += TemporaryVehicle_PlayerEnter;
}
public void CreateTimer()
{
Timer timer = new Timer(1000, true);
timer.Tick += (tO, tE) =>
{
if (this.Player != null)
{
if (!this.Player.IsConnected || !this.Player.IsInVehicle(this))
{
if (!this.Disposed)
{
this.Dispose();
}
}
else if (!this.Disposed)
{
return;
}
timer.Dispose();
}
};
}
private void TemporaryVehicle_PlayerEnter(object sender, SampSharp.GameMode.Events.PlayerVehicleEventArgs e)
{
if (this.Player == null)
{
e.Player.StateChanged += Player_StateChanged;
}
}
private void Player_StateChanged(object sender, SampSharp.GameMode.Events.PlayerStateEventArgs e)
{
if (e.NewState == PlayerState.Driving || e.NewState == PlayerState.Passenger)
{
this.PlayerEnter -= TemporaryVehicle_PlayerEnter;
e.Player.StateChanged -= Player_StateChanged;
this.Player = e.Player as StorablePlayer;
}
}
public static Vehicle Create(int vehicletype, Vector position, float rotation, int color1, int color2, int respawnDelay, StorablePlayer player)
{
TemporaryVehicle veh = TemporaryVehicle.Create(vehicletype, position, rotation, color1, color2, respawnDelay) as TemporaryVehicle;
if (player != null)
{
veh.Player = player;
}
return veh;
}
public static Vehicle Create(VehicleModelType vehicletype, Vector position, float rotation, int color1, int color2, int respawnDelay, StorablePlayer player)
{
return TemporaryVehicle.Create((int)vehicletype, position, rotation, color1, color2, respawnDelay, player);
}
}
}
and i'm calling it by
float rotation = p.Rotation.Z;
if (p.InAnyVehicle)
{
rotation = p.Vehicle.Rotation.Z;
}
Vehicle veh = TemporaryVehicle.Create(400, p.Position, rotation, -1, -1, -1, p);
On my local branch I have no problems with Player.PutPlayerInVehicle. This might be due to my local branch being 30 commits ahead of this repo's master branch. I'm currently on vacation, unable to push and I will check what the problem is when I'm back home(+-3 weeks from now). As a temporary fix you might want to try Native.PutPlayerInVehicle(...).
I'll take the -3 weeks from now :dancers: Yeah i will try it :)
Enjoy your holiday!
Managed it by the way, by setting the virtual world and the interior,
My server crashes when putting a player in a vehicle that was just created.
The crashdetect plugin says:
[00:55:43] [debug] Server crashed due to an unknown error [00:55:43] [debug] Native backtrace: [00:55:43] [debug] #0 0f94c0fb in SampSharp::HandleEvent () from plugins\SampSharp.DLL [00:55:43] [debug] #1 0f95bdf3 in OnPublicCall () from plugins\SampSharp.DLL [00:55:43] [debug] #2 0f927ce2 in sampgdk_callback_invoke () from plugins\SampSharp.DLL [00:55:43] [debug] #3 0f929354 in sampgdk_param_get_string () from plugins\SampSharp.DLL [00:55:43] [debug] #4 0046dcdb in ?? () from samp-server.exe [00:55:43] [debug] #5 0047f68b in ?? () from samp-server.exe [00:55:43] [debug] #6 0047833c in ?? () from samp-server.exe [00:55:43] [debug] #7 65aa923c in ?? () from mono-2.0.dll [00:55:43] [debug] #8 65a631a7 in ?? () from mono-2.0.dll [00:55:43] [debug] #9 0f9287dc in sampgdk_native_find_warn_stub () from plugins\SampSharp.DLL [00:55:43] [debug] #10 0f977db0 in std::_Facetptrstd::ctype::_Psave () from plugins\SampSharp.DLL
[00:55:43] [debug] #11 0018e784 in ?? ()