Write past end of buffer error when sending byte[] using SendNamedMessage
See original GitHub issueDescription
This bug is about Custom Messages. When trying to send a byte[] Using SendNamedMessage you get a “Write past end of buffer error”
Reproduce Steps
- Write a script that sends a simple byte[] to a client.
- The FastBufferArray will write perfectly fine, but The SendNamedMessage will get an “Write past end of buffer error”;
Actual Outcome
SendNamedMessage with a byte[] will give an error
Expected Outcome
The written FastBufferArray will be send without issue
My code:
public void SendChunkMessage(byte[] messageContent, ulong clientID)
{
int writeSize = FastBufferWriter.GetWriteSize(messageContent);
FastBufferWriter writer = new FastBufferWriter(writeSize, Allocator.Temp);
CustomMessagingManager customMessagingManager = NetworkManager.CustomMessagingManager;
using (writer)
{
writer.TryBeginWrite(writeSize);
writer.WriteBytes(messageContent, writeSize, 0);
Debug.Log("Written to FastBufferWriter");
if (IsServer)
{
customMessagingManager.SendNamedMessage("Chunk", clientID, writer);
}
}
Debug.Log("Send to client");
}
My error:
Environment
- OS: Windows 10 pro
- Unity Version: 2022.2.0b16
- Netcode Version: 1.1.0
Issue Analytics
- State:
- Created 9 months ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Issue sending dynamic data. Possibly bad design on my ...
OverflowException: Writing past the end of the buffer. Here's my code: Code (CSharp):. public void SendNamedMessage(CustomNamedMessage ...
Read more >Error buffer_update: Attempted to write buffer (24576 bytes) ...
Issue description. E 0:00:02:0352 buffer_update: Attempted to write buffer (24576 bytes) past the end. <C++ 错误> Condition ...
Read more >How to send a byte[] with buffer to a server?
I try to send a byte[] with an ssl socket and a buffer to my server, but doesn't succeed the buffer. I search...
Read more >Attempting to read from outside the buffer error when high ...
Hi, I am making a multiplayer game which works perfectly fine 95% of the time however occasionally the game will start having higher...
Read more >Struct FastBufferWriter | Netcode for GameObjects | 1.0.2
Returns an array representation of the underlying byte buffer. ... Instead, attempting to write past the marked position in release builds ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Very belated response… Sorry about that.
The default value of -1 is not actually intended to be an “infinite growth” value. Note the documentation:
The default of -1 is always going to be less than the size. Constructing without a third argument isn’t intended to create an infinite-growth buffer - the default behavior is a non-growing buffer that won’t exceed the size you give it.
Oh sorry my comment was unrelated to this actual issue, it was specifically about the default -1 value. Just tested it in my project when I saw Noel’s message, I tried it again now just to see (in case it was bugged before cause it had never worked for me).
This works fine (the size of values is 16)
This won’t work and will throw a “Write past end of buffer” exception. (the size of values is 16)