Access to member causes crash

Openplanet is an alternative scripting platform for the ManiaPlanet creative community.

Moderators: Miss, NADEO

Post Reply
User avatar
Derfuhr
Posts: 55
Joined: 18 May 2017, 17:08
Location: DE->NRW

Access to member causes crash

Post by Derfuhr » 30 Nov 2019, 16:17

Hi,

when i access a member an exception occurs. (CTrackManiaPlayer.RaceState)

Code: Select all

ERaceState currentRaceState = player.RaceState;
Image

this happens when a map is loaded and switching to ERaceState::BeforeStart or the script is started while in race.

I'm using this Code:

Code: Select all

#name "Gauge"
#author "Derfuhr aka ClumsySmurf"
#category "Clumsy's Plugins"

bool debug = true; // developer option

[Setting name="Active" description="Addon activation-state"]
bool active = false;

[Setting name="Position X" description="base position X"]
float positionX = 500.0f;

[Setting name="Position Y" description="base position Y"]
float positionY = 150.0f;;

[Setting name="Color R" description="Color R value"]
float r = 1.0f;

[Setting name="Color G" description="Color G value"]
float g = 0.0f;

[Setting name="Color B" description="Color B value"]
float b = 0.0f;

[Setting name="Color A" description="Color A value"]
float a = 1.0f;

bool windowIsVisible = false;
bool raceIsRunning = false;
int speed = 0;
string login = "";

void main()
{

}

void RenderMenu()
{
	if (UI::MenuItem("Gauge", "", active))
	{
		windowIsVisible = !windowIsVisible;
	}
}

void Render()
{
	if(active || UI::IsOverlayShown())
	{
		CGameCtnApp@ app = cast<CGameCtnApp>(GetApp());
		if(app !is null)
		{
			CGamePlayerProfile@ CurrentProfile = app.CurrentProfile;
			if(CurrentProfile !is null)
			{
				CGamePlayerProfileChunk_AccountSettings@ AccountSettings = CurrentProfile.AccountSettings;
				if(AccountSettings !is null)
				{					
					login = AccountSettings.OnlineLogin;
					if(login != "")
					{						
						CTrackManiaRaceNew@ PlaygroundScript = cast<CTrackManiaRaceNew>(app.CurrentPlayground);
						if(PlaygroundScript !is null)
						{
							MwBuffer<CGamePlayer@> Players = PlaygroundScript.Players;						
							for(uint i = 0; i < Players.get_Length(); i++) 
							{
								CTrackManiaPlayer@ player = cast<CTrackManiaPlayer>(Players[i]);
								if(player !is null)
								{
									CTrackManiaPlayerInfo@ playerInfo = cast<CTrackManiaPlayerInfo>(player.User);
									if(playerInfo.Login == login)
									{

										//raceIsRunning = (player.RaceState == ERaceState::Running)
										ERaceState currentRaceState = player.RaceState;
										//if(state == player.RaceState)
										//{
											//raceIsRunning = true;
										//}
										//else
										//{
											//raceIsRunning = false;
										//}				
										//speed = player.DisplaySpeed;									
									}
								}
								else 
								{
									onError("player null");
								}								
							}
						}
						else
						{				
							onError("PlaygroundScript null");
						}
					}
					else 
					{
						onError("Login string empty");
					}
				}
				else
				{
					onError("accountsetting null");
				}				
			}
			else
			{	
				onError("CurrentProfile null");
			}
		} 
		else
		{			
			onError("app null");
		}
		if((active && raceIsRunning) || (UI::IsOverlayShown() && windowIsVisible))
		{
			vec2 pos = vec2(positionX, positionY);
			vec4 color = vec4(r, g, b, a);
			//Drawing.....
		}

	}						
}

void RenderInterface()
{	
	if(!windowIsVisible)
	{
		return;
	}
	UI::SetNextWindowPos(40, 40);
	UI::SetNextWindowSize(350, 350);
	UI::Begin("Gauge by ClumsySmurf", windowIsVisible, UI::WindowFlags::NoResize);
	active = UI::Checkbox("Plugin active", active);
	UI::Text("Position: (Center of the Gauge)");
	positionX = UI::InputFloat("X", positionX, 0.5f);
	positionY = UI::InputFloat("Y", positionY, 0.5f);
	positionX = checkRange(positionX, 0.0f, float(Draw::GetWidth()));
	positionY = checkRange(positionY, 0.0f, float(Draw::GetHeight()));	
	UI::Text("Color:");
	r = UI::InputFloat("R", r, 0.001f); 	
	g = UI::InputFloat("G", g, 0.001f);
	b = UI::InputFloat("B", b, 0.001f);
	a = UI::InputFloat("A", a, 0.001f);
	r = checkRange(r, 0.0f, 1.0f);
	g = checkRange(g, 0.0f, 1.0f);
	b = checkRange(b, 0.0f, 1.0f);
	a = checkRange(a, 0.0f, 1.0f);	
	UI::End();
}

int checkRange(int value, int min, int max)
{
	if(value < min)
	{
		value = min;
	}
	if(value > max)
	{
		value = max;
	}
	return value;
}

float checkRange(float value, float min, float max)
{
	if(value < min)
	{
		value = min;
	}
	if(value > max)
	{
		value = max;
	}
	return value;
}

void onError(string text)
{
	if(debug)
	{	
		print(text);
	}
}


User avatar
Miss
Posts: 1951
Joined: 05 Jan 2016, 11:34
Location: The Netherlands
Contact:

Re: Access to member causes crash

Post by Miss » 30 Nov 2019, 19:14

Which version of Openplanet are you running?
1070 GTX, Ryzen 3700X, 16GB RAM, Windows 10
Forum moderator, opinions are my own. :thx:
Check out Image openplanet, the alternative ManiaPlanet & Turbo scripting platform! (Openplanet subforum)
I also stream on Twitch and tweet on Twitter.

User avatar
Derfuhr
Posts: 55
Joined: 18 May 2017, 17:08
Location: DE->NRW

Re: Access to member causes crash

Post by Derfuhr » 30 Nov 2019, 19:41

I'm using 1.13.3 build v4 (ManiaPlanet)

User avatar
Miss
Posts: 1951
Joined: 05 Jan 2016, 11:34
Location: The Netherlands
Contact:

Re: Access to member causes crash

Post by Miss » 01 Dec 2019, 12:17

Thanks, I'll check it out. I asked because I fixed a similar bug in the latest update.
1070 GTX, Ryzen 3700X, 16GB RAM, Windows 10
Forum moderator, opinions are my own. :thx:
Check out Image openplanet, the alternative ManiaPlanet & Turbo scripting platform! (Openplanet subforum)
I also stream on Twitch and tweet on Twitter.

Post Reply

Return to “Openplanet”

Who is online

Users browsing this forum: No registered users and 2 guests