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

f the number of filters is zero, it will cause a program crash in .NET 6 #749

Open
tkzcxl opened this issue Dec 24, 2023 · 0 comments
Open
Assignees

Comments

@tkzcxl
Copy link

tkzcxl commented Dec 24, 2023

Describe the bug
In .NET 6, if the number of filters is zero, it will cause the program to crash. However, in the .NET Framework, this will not happen

To Reproduce
Occurs immediately when the following code is called

Calling Code

var Request = new Steamworks.ServerList.Internet();
Request.OnChanges += () =>
{
	if ( Request.Responsive.Count == 0 )
		return;
	foreach ( var s in Request.Responsive )
	{
		Console.WriteLine(s.Name);
	}
	Request.Responsive.Clear();
};
Request.RunQueryAsync( 30 );

Expected behavior
no happen.

Desktop (please complete the following information):

  • OS: windows11

Additional context
his error is triggered by the ISteamMatchmakingServers.RequestInternetServerList() function. It is suspected that there may have been changes in the new version of C# ref struct. After limiting the number of MatchMakingKeyValuePair[] ppchFilters to at least one, this issue no longer occurs

Try Fix Code

private MatchMakingKeyValuePair[] ppchFiltersEmpty = new MatchMakingKeyValuePair[] {new MatchMakingKeyValuePair()};
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamMatchmakingServers_RequestInternetServerList", CallingConvention = Platform.CC)]
private static extern HServerListRequest _RequestInternetServerList( IntPtr self, AppId iApp, [In,Out] ref MatchMakingKeyValuePair[]  ppchFilters, uint nFilters, IntPtr pRequestServersResponse );

#endregion
internal HServerListRequest RequestInternetServerList( AppId iApp, [In,Out] ref MatchMakingKeyValuePair[]  ppchFilters, uint nFilters, IntPtr pRequestServersResponse )
{
	var returnValue = ppchFilters.Length == 0  
		? _RequestInternetServerList( Self, iApp, ref ppchFiltersEmpty, nFilters, pRequestServersResponse ) 
		: _RequestInternetServerList( Self, iApp, ref ppchFilters, nFilters, pRequestServersResponse );
	return returnValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants