// ByteVector gets a byte slice from data stored inside the flatbuffer.
func (t *Table) ByteVector(off UOffsetT) []byte {
off += GetUOffsetT(t.Bytes[off:])
start := off + UOffsetT(SizeUOffsetT)
length := GetUOffsetT(t.Bytes[off:])
return t.Bytes[start : start+length]
}
panic: runtime error: slice bounds out of range
how to avoid it panic?
Yes, it is intended to panic on invalid data, as it may have offsets that point to outside the buffer. We do not want to do manual error checking on each access for performance and API simplicity.
In C++ we have an additional verifier that can tell if a buffer is safe to read before accessing it (because C++ has no bounds checking at all). This could be ported to Go if that is useful.
@rw who wrote the Go port.
thanks reply, now we plan to use golang's recover to catch panics in each fuction
@GStones did you get your issue resolved? If not, please post your schema file so we can take a look.
include "Common.fbs";
namespace msg_fbs;
enum HallMessage:int32 {
CGEnterHall= 20000,
GCEnterHall,
CGMatchBattle,
GCMatchBattle,
GCMatchOver,
CGCancelMatchBattle,
GCCancelMatchBattle,
GCHallAddPlayer,
GCHallRemovePlayer,
CGLeaveHall,
GCLeaveHall,
CGHallPlayerReady,
GCHallPlayerReady,
CGHallPlayerCancelReady,
GCHallPlayerCancelReady,
CGHallTransferTeamOwner,
GCHallUpdateTeamOwner,
}
enum HallErrCode : byte {
Success = 0,
NotLogin,
NotExist,
NotFound,
AlreadyIn,
OverMax,
LogicErr,
DataErr,
NotReady
}
table HallRole{
UID:string;
SeatID:int32;
Name:string;
Gender:RoleGender;
Avatar:int32;
StarLevel:int32;
Team:BattleTeam;//delete
RankStage:int32;
RankLevel:int32;
}
enum BattleLevel:byte{Esay = 0,Normal,Hard}
table CGEnterHall{
UID:string;//delete
MatchMode:MatchMode;
TargetUID:string;
}
table GCEnterHall{
Code:HallErrCode;
}
table CGCancelMatchBattle{}
table GCCancelMatchBattle{
Code:HallErrCode;
}
table CGMatchBattle {}
table GCMatchBattle {
Code:HallErrCode;
Duration:int64; //second
}
table GCMatchOver{
RoomID:int64;
Roles:[HallRole];// delete
}
//------------Team-------------------
table GCHallAddPlayer{
Roles:[HallRole];
}
table GCHallRemovePlayer{
UID:string;
}
table GCHallUpdateTeamOwner{
UID:string;
}
table CGHallTransferTeamOwner{
UID:string;
}
table CGLeaveHall{
TeamID:string;//new
}
table GCLeaveHall{
Code:HallErrCode;
}
table CGHallPlayerReady{}
table GCHallPlayerReady{
UID:string;
}
table CGHallPlayerCancelReady{}
table GCHallPlayerCancelReady{
UID:string;
}
when client send error data,the server will panic with _runtime error: slice bounds out of range_
Sorry, I didn’t respond in time.
This issue has been automatically marked as stale because it has not had activity for 1 year. It will be automatically closed if no further activity occurs. To keep it open, simply post a new comment. Maintainers will re-open on new activity. Thank you for your contributions.
don‘t leave me alone,this still not resolve
@GStones what would resolve this? You have 3 possible solutions:
ok! thanks for your reply.