• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Buffers not working properly

H

Hyteel

Guest
Hello, I am working on a multiplayer-project and have stumbled upon a strange error. I am getting "Attempting to read from outside the buffer, returning 0" from my code, and I cant seem to understand why. This is the code that sends the buffer:


//Send to player
buffer_seek(ServerBuffer, buffer_seek_start, 0);
buffer_write(ServerBuffer, buffer_u8, Network.SUpdateSelf); //u8
buffer_write(ServerBuffer, buffer_u8, Ypos); //u8
buffer_write(ServerBuffer, buffer_u8, LayerId); //u8
buffer_write(ServerBuffer, buffer_u16, ds_grid_get(ClientValues, 1, Ypos)) //u16
buffer_write(ServerBuffer, buffer_u16, ds_grid_get(ClientValues, 2, Ypos)) //u16
network_send_packet(ds_list_find_value(Clients, Ypos), ServerBuffer, buffer_tell(ServerBuffer));


and this is the one that receives it:


case Network.SUpdateSelf: //Receive SUpdate //u8
var Client = buffer_read(Buffer, buffer_u8); //u8
global.LayerId = buffer_read(Buffer, buffer_u8); //u8
ds_grid_set(global.ClientValue_Clientside, 1, Client, buffer_read(Buffer, buffer_u16)); //u16
ds_grid_set(global.ClientValue_Clientside, 2, Client, buffer_read(Buffer, buffer_u16)); //u16


I have tried rearranging it and finding out ways to solve it myself but to no awail, it is probably something I wrote wrong but I have been looking at the code for about half an hour now.
It is supposed to send 3 u8s and 2 u16s and then receive 3 u8s and 2 u16s and it seems to look like it should work in the code but the last one on the receiving end always reads outside of the buffer.
 

Nidoking

Member
What comes before the receive part you're showing? You didn't include the buffer_read that gets the Network.SUpdateSelf value.
 
H

Hyteel

Guest
The first buffer that gets Network.SUpdateSelf is like this:
MsgId = buffer_read(Buffer, buffer_u8);

and everything is part of a switch:
switch(MsgId)
with propper use of break;

Everything worked fine untill i Added:

buffer_write(ServerBuffer, buffer_u8, LayerId); //u8 in serverside

and

global.LayerId = buffer_read(Buffer, buffer_u8); //u8 in clientside

If I remove them everything starts working again
 

chamaeleon

Member
The first buffer that gets Network.SUpdateSelf is like this:
MsgId = buffer_read(Buffer, buffer_u8);

and everything is part of a switch:
switch(MsgId)
with propper use of break;

Everything worked fine untill i Added:

buffer_write(ServerBuffer, buffer_u8, LayerId); //u8 in serverside

and

global.LayerId = buffer_read(Buffer, buffer_u8); //u8 in clientside

If I remove them everything starts working again
Are you sure you're running the right version of the server? Any chance at all you're running an old version that is not recompiled with the extra data to be added to the buffer?
 
H

Hyteel

Guest
I am running the right version, removing: buffer_write(ServerBuffer, buffer_u8, LayerId); //u8 in serverside and global.LayerId = buffer_read(Buffer, buffer_u8); //u8 in clientside
makes everything work again so it has to be something with them
 
H

Hyteel

Guest
I restarted it and it started working again for some reason. Thanks for the help!
 
Top