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

SteamNetworking.isP2PPacketAvailable generates error in native code #108

Open
andy98725 opened this issue Jan 12, 2022 · 3 comments
Open

Comments

@andy98725
Copy link

andy98725 commented Jan 12, 2022

In one use case, the mentioned function consistently errors out.

Here's my relevant code. Let me know if there's an alternative way I should be using the method.

private Thread startListener() {
	Thread listen = new Thread(new Runnable() {
		@Override
		public void run() {
			SteamNetworking net = steam.net.get();
			SteamID sender = new SteamID();
			int msgSize;

			try {
				while (!Thread.interrupted()) {
					try {
						while ((msgSize = net.isP2PPacketAvailable(0)) > 0) {
							if (msgSize > recBuffer.capacity())
							recBuffer = ByteBuffer.allocateDirect(msgSize);

							synchronized (recBuffer) {
									recBuffer.clear();
									net.readP2PPacket(sender, recBuffer, 0);
									byte[] bytes = new byte[msgSize];
									recBuffer.get(bytes);
									recieveMessage(FileUtils.bytesToObj(bytes), sender);
							}
						}
					} catch (Exception e) {
						Game.getLogger().errorLog(e, "Steam Game Listener");
					}
					Thread.sleep((long) (1000.0 / Game.FRAME_RATE));
				}
			} catch (InterruptedException e) {
			}
		}
	}, "Steam Game Listener");
	listen.setDaemon(true);
	listen.start();
	return listen;
}

Here's the error log, since I'm on Windows:
hs_err_pid18664.log

@code-disaster
Copy link
Owner

I don't know why it would crash inside the isP2PPacketAvailable() function, but I agree that the Java API could do a better job here. I believe there's also a bug with readP2PPacket() - it should check the return value and limit() recBuffer accordingly afterwards. (The same bug exists in SteamNetworkingTest)

@code-disaster
Copy link
Owner

Also, not sure what your steam.net.get() does, and how many of those listeners you create, but you may run into trouble here. Try to not share that SteamNetworking instance, but just create a local one.

@andy98725
Copy link
Author

Ah, that line just lazy-loads the interface. There's only the one interface and it's disposed of properly, so no issues there.

I found the presence of the error strange due to the simplicity of the C method. I have no idea what could cause it. Doesn't help that the windows error reporting for the native code is borderline unreadable to me.

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