ddevault / TrueCraft

Minecraft for hipsters
http://truecraft.io/
MIT License
2.4k stars 312 forks source link

Crash at startup #268

Closed WhyNotHugo closed 7 years ago

WhyNotHugo commented 7 years ago

I'm running ArchLinux, and the latest master crashes when I try to start a game on a new world:

$ truecraft

(TrueCraft.Launcher:3295): Gtk-WARNING **: Unable to locate theme engine in module_path: "adwaita",

(TrueCraft.Launcher:3295): Gtk-WARNING **: Unable to locate theme engine in module_path: "adwaita",
2017-05-24 4:34:59    Notice     Generating world around spawn point...
2017-05-24 4:35:00    Notice     10% complete
2017-05-24 4:35:01    Notice     20% complete
2017-05-24 4:35:02    Notice     30% complete
2017-05-24 4:35:02    Notice     40% complete
2017-05-24 4:35:03    Notice     50% complete
2017-05-24 4:35:04    Notice     60% complete
2017-05-24 4:35:05    Notice     70% complete
2017-05-24 4:35:06    Notice     80% complete
2017-05-24 4:35:07    Notice     90% complete
2017-05-24 4:35:09    Notice     100% complete
2017-05-24 4:35:09    Notice     Simulating the world for a moment...
2017-05-24 4:35:09    Notice     10% complete
2017-05-24 4:35:09    Notice     20% complete
2017-05-24 4:35:09    Notice     30% complete
2017-05-24 4:35:09    Notice     40% complete
2017-05-24 4:35:09    Notice     50% complete
2017-05-24 4:35:09    Notice     60% complete
2017-05-24 4:35:09    Notice     70% complete
2017-05-24 4:35:09    Notice     80% complete
2017-05-24 4:35:09    Notice     90% complete
2017-05-24 4:35:09    Notice     100% complete
2017-05-24 4:35:09    Notice     Running TrueCraft server on 127.0.0.1:36443
2017-05-24 4:35:09    Warning    Lighting queue is backed up
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
2017-05-24 4:35:10    Warning    Lighting queue is backed up
2017-05-24 4:35:10    Warning    Lighting queue is backed up
2017-05-24 4:35:10    Warning    Lighting queue is backed up
2017-05-24 4:35:10    Warning    Lighting queue is backed up
2017-05-24 4:35:10    Warning    Lighting queue is backed up
2017-05-24 4:35:10    Warning    Lighting queue is backed up
2017-05-24 4:35:11    Warning    Lighting queue is backed up
2017-05-24 4:35:11    Warning    Lighting queue is backed up
2017-05-24 4:35:11    Warning    Lighting queue is backed up
2017-05-24 4:35:11    Warning    Lighting queue is backed up
2017-05-24 4:35:11    Warning    Lighting queue is backed up

Unhandled Exception:
System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
  at System.Buffer.BlockCopy (System.Array src, System.Int32 srcOffset, System.Array dst, System.Int32 dstOffset, System.Int32 count) [0x00097] in <73ee1b14c2fa4d61b481096ff3d8d6d7>:0
  at TrueCraft.Client.Handlers.ChunkHandlers.HandleChunkData (TrueCraft.API.Networking.IPacket _packet, TrueCraft.Client.MultiplayerClient client) [0x000a2] in <9374469e37fa451fa1cf5baf82325afc>:0
  at TrueCraft.Client.MultiplayerClient.ProcessNetwork (System.Net.Sockets.SocketAsyncEventArgs e) [0x000c0] in <9374469e37fa451fa1cf5baf82325afc>:0
  at TrueCraft.Client.MultiplayerClient.OperationCompleted (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00022] in <9374469e37fa451fa1cf5baf82325afc>:0
  at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) [0x0000e] in <2fef7234205a4a009fe5995569c314ee>:0
  at System.Net.Sockets.SocketAsyncEventArgs.Complete () [0x00000] in <2fef7234205a4a009fe5995569c314ee>:0
  at System.Net.Sockets.Socket+<>c.<.cctor>b__306_7 (System.IAsyncResult ares) [0x0005d] in <2fef7234205a4a009fe5995569c314ee>:0
  at System.Net.Sockets.SocketAsyncResult+<>c__DisplayClass27_0.<Complete>b__0 (System.Object _) [0x00000] in <2fef7234205a4a009fe5995569c314ee>:0
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00008] in <73ee1b14c2fa4d61b481096ff3d8d6d7>:0
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <73ee1b14c2fa4d61b481096ff3d8d6d7>:0
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <73ee1b14c2fa4d61b481096ff3d8d6d7>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
  at System.Buffer.BlockCopy (System.Array src, System.Int32 srcOffset, System.Array dst, System.Int32 dstOffset, System.Int32 count) [0x00097] in <73ee1b14c2fa4d61b481096ff3d8d6d7>:0
  at TrueCraft.Client.Handlers.ChunkHandlers.HandleChunkData (TrueCraft.API.Networking.IPacket _packet, TrueCraft.Client.MultiplayerClient client) [0x000a2] in <9374469e37fa451fa1cf5baf82325afc>:0
  at TrueCraft.Client.MultiplayerClient.ProcessNetwork (System.Net.Sockets.SocketAsyncEventArgs e) [0x000c0] in <9374469e37fa451fa1cf5baf82325afc>:0
  at TrueCraft.Client.MultiplayerClient.OperationCompleted (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00022] in <9374469e37fa451fa1cf5baf82325afc>:0
  at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) [0x0000e] in <2fef7234205a4a009fe5995569c314ee>:0
  at System.Net.Sockets.SocketAsyncEventArgs.Complete () [0x00000] in <2fef7234205a4a009fe5995569c314ee>:0
  at System.Net.Sockets.Socket+<>c.<.cctor>b__306_7 (System.IAsyncResult ares) [0x0005d] in <2fef7234205a4a009fe5995569c314ee>:0
  at System.Net.Sockets.SocketAsyncResult+<>c__DisplayClass27_0.<Complete>b__0 (System.Object _) [0x00000] in <2fef7234205a4a009fe5995569c314ee>:0
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00008] in <73ee1b14c2fa4d61b481096ff3d8d6d7>:0
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <73ee1b14c2fa4d61b481096ff3d8d6d7>:0
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <73ee1b14c2fa4d61b481096ff3d8d6d7>:0
AL lib: (EE) alc_cleanup: 2 devices not closed
2017-05-24 4:35:11    Notice     - has left the server.
2017-05-24 4:35:11    Warning    Lighting queue is backed up
2017-05-24 4:35:11    Warning    Lighting queue is backed up

I'm on ArchLinux-amd64, with intel video.

ddevault commented 7 years ago

Does this happen consistently? Can you describe reproduction steps in more detail?

WhyNotHugo commented 7 years ago

I can reproduce this consistently: it happens every single time. Steps are (sorry if this is stupidly verbose, but I just in case):

Selecting a pre-existing world has the same result.

I believe these dependencies are relevant:

I also tried deleting ~/.config/truecraft.

ddevault commented 7 years ago

I can reproduce. Will look into it.

BearzRobotics commented 7 years ago

I've been getting the same error as well. When I try to just run the client I got this as an output.

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array. at TrueCraft.Client.Program.Main (System.String[] args) [0x0001c] in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.IndexOutOfRangeException: Index was outside the bounds of the array. at TrueCraft.Client.Program.Main (System.String[] args) [0x0001c] in :0

tugh commented 7 years ago

I'm having the same issue with @hobarrera

erherhh4herh commented 7 years ago

same issue with @BearzRobotics i think this game is dead. too bad prob no fix.

ddevault commented 7 years ago

Send me a patch and I'll merge it.

flibitijibibo commented 7 years ago

Ended up figuring this out by accident. The fast path for HandleChunkData seems to assume the chunk size when it may, for example, only have block IDs without metadata, light, or sky light. This fixes the crash for me, but I'm guessing the packet is supposed to have all of these things...?

diff --git a/TrueCraft.Client/Handlers/ChunkHandlers.cs b/TrueCraft.Client/Handlers/ChunkHandlers.cs
index 254299f..ede145a 100644
--- a/TrueCraft.Client/Handlers/ChunkHandlers.cs
+++ b/TrueCraft.Client/Handlers/ChunkHandlers.cs
@@ -52,16 +52,31 @@ namespace TrueCraft.Client.Handlers
                 && packet.Height == Chunk.Height
                 && packet.Depth == Chunk.Depth) // Fast path
             {
+                // Chunk data offsets
+                int metadataOffset = chunk.Data.Length;
+                int lightOffset = metadataOffset + chunk.Metadata.Length;
+                int skylightOffset = lightOffset + chunk.BlockLight.Length;
+
                 // Block IDs
                 Buffer.BlockCopy(data, 0, chunk.Data, 0, chunk.Data.Length);
                 // Block metadata
-                Buffer.BlockCopy(data, chunk.Data.Length, chunk.Metadata.Data, 0, chunk.Metadata.Data.Length);
+                if (metadataOffset < data.Length)
+                {
+                    Buffer.BlockCopy(data, metadataOffset,
+                        chunk.Metadata.Data, 0, chunk.Metadata.Data.Length);
+                }
                 // Block light
-                Buffer.BlockCopy(data, chunk.Data.Length + chunk.Metadata.Data.Length,
-                    chunk.BlockLight.Data, 0, chunk.BlockLight.Data.Length);
+                if (lightOffset < data.Length)
+                {
+                    Buffer.BlockCopy(data, lightOffset,
+                        chunk.BlockLight.Data, 0, chunk.BlockLight.Data.Length);
+                }
                 // Sky light
-                Buffer.BlockCopy(data, chunk.Data.Length + chunk.Metadata.Data.Length + chunk.BlockLight.Data.Length,
-                    chunk.SkyLight.Data, 0, chunk.SkyLight.Data.Length);
+                if (skylightOffset < data.Length)
+                {
+                    Buffer.BlockCopy(data, skylightOffset,
+                        chunk.SkyLight.Data, 0, chunk.SkyLight.Data.Length);
+                }
             }
             else // Slow path
             {
ddevault commented 7 years ago

Can you send this as a pull request instead of a diff thrown into a commit? You can email me a patch if you want, too.

flibitijibibo commented 7 years ago

Done: https://github.com/SirCmpwn/TrueCraft/pull/282

erherhh4herh commented 7 years ago

Using latest commit still warrants the same effect. However, I want to note that this happens regardless of offline, or online mode and whether or not I load an already generated world. I am also compiling on VS 2017. Does the same with the precompiled binaries available on the website, with no errors.

lanodan commented 7 years ago

Weird, on my side it runs fine.

Do you actually have the same error?