code-disaster / steamworks4j

A thin Java wrapper to access the Steamworks API
https://code-disaster.github.io/steamworks4j/
MIT License
479 stars 67 forks source link

Crashes while attempting to write to remote storage. #55

Closed SneakySly closed 7 years ago

SneakySly commented 7 years ago

Hey there, I am attempting to utilize steam cloud by writing a chunk to an open stream. After appearing to open a file stream successfully my application crashes when I run:

ByteBuffer writeBuffer = ByteBuffer.allocate(100);
String mockFileContents = "This is a test of remote file writes.";
writeBuffer.put(mockFileContents.getBytes());
SteamUGCFileWriteStreamHandle filestream = steamCloud.fileWriteStreamOpen(remoteFilename);
steamCloud.fileWriteStreamWriteChunk(filestream, writeBuffer, 100); //FAILS HERE
steamCloud.fileWriteStreamClose(filestream);

When looking at the exception when the JVM crashes I see:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000005080863b, pid=3756, tid=0x0000000000000f78
#
# JRE version: Java(TM) SE Runtime Environment (8.0_131-b11) (build 1.8.0_131-b11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.131-b11 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [steamclient64.dll+0x7b863b]

Also here are the stack frames:

Stack: [0x0000000020aa0000,0x0000000020f70000],  sp=0x0000000020f6ef48,  free space=4923k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [steamclient64.dll+0x7b863b]
C  [steamclient64.dll+0x636003]
C  [steamclient64.dll+0x374049]
C  [steamclient64.dll+0x34cb21]
C  0x0000000003be5c74

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  com.codedisaster.steamworks.SteamRemoteStorage.fileWriteStreamWriteChunk(JJLjava/nio/ByteBuffer;I)Z+0
j  com.codedisaster.steamworks.SteamRemoteStorage.fileWriteStreamWriteChunk(Lcom/codedisaster/steamworks/SteamUGCFileWriteStreamHandle;Ljava/nio/ByteBuffer;I)Z+10
j  com.megacrit.cardcrawl.steam.SteamSaveSync.syncFileToCloud(Ljava/lang/String;Ljava/lang/String;)V+230
j  com.megacrit.cardcrawl.core.CardCrawlGame.create()V+344
j  com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop()V+29
j  com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run()V+27
v  ~StubRoutines::call_stub

We are using the latest version of steamworks4j (1.6.2).

code-disaster commented 7 years ago

ByteBuffer writeBuffer = ByteBuffer.allocate(100);

You must use a direct byte buffer. Java heap allocations won't work here. The function doesn't check for that yet.

SneakySly commented 7 years ago

Thanks for the help! It no longer crashes after changing to:

ByteBuffer writeBuffer = ByteBuffer.allocateDirect(mockFileContents.getBytes().length);

Now my problem is that the remote file is not being created (or being written too), but that is a separate issue.