Raised This Month: $32 Target: $400
 8% 

Solved Bot Mimic: Enum Structs (Invalid Handle)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LeeStrong
AlliedModders Donor
Join Date: Nov 2015
Old 04-17-2020 , 14:06   Bot Mimic: Enum Structs (Invalid Handle)
Reply With Quote #1

Hi all,
I am working on a project at the moment that uses "Bot Mimic" to record and play replay bots.

The coded has been updated to the new syntax however the following error gets tripped;

ERROR
Code:
[SM] Exception reported: Invalid Handle 0 (error: 4)
[SM] Blaming: surftimer.smx
[SM] Call stack trace:
[SM]   [0] PushArrayArray
[SM]   [1] Line 644, surftimer/replay.sp::LoadRecordFromFile
[SM]   [2] Line 432, surftimer/replay.sp::PlayRecord
[SM]   [3] Line 721, surftimer/replay.sp::LoadRecordReplay
[SM]   [4] Line 683, surftimer/replay.sp::RefreshBot
I was wondering if anyone could possibly look at these segments of code, before/after the new syntax and ask if you would have done anything differently, or spot something I perhaps didn't that may cause the above error?

Quote:
Originally Posted by BEFORE
Code:
	Handle hRecordFrames = CreateArray(view_as<int>(FrameInfo));
	Handle hAdditionalTeleport = CreateArray(AT_SIZE);

	int iFrame[FRAME_INFO_SIZE];
	for (int i = 0; i < iTickCount; i++)
	{
		ReadFile(hFile, iFrame, view_as<int>(FrameInfo), 4);
		PushArrayArray(hRecordFrames, iFrame, view_as<int>(FrameInfo));
Quote:
Originally Posted by AFTER
Code:
	Handle hRecordFrames = CreateArray(sizeof(FrameInfo));
	Handle hAdditionalTeleport = CreateArray(sizeof(AdditionalTeleport));
	FrameInfo iFrame;
	for (int i = 0; i < iTickCount; i++)
	{
		ReadFile(hFile, iFrame.PlayerButtons, sizeof(FrameInfo), 4);
		ReadFile(hFile, iFrame.PlayerImpulse, sizeof(FrameInfo), 4);
		ReadFile(hFile, view_as<int>(iFrame.ActualVelocity), sizeof(FrameInfo), 4);
		ReadFile(hFile, view_as<int>(iFrame.PredictedVelocity), sizeof(FrameInfo), 4);
		ReadFile(hFile, view_as<int>(iFrame.PredictedAngles), sizeof(FrameInfo), 4);
		ReadFile(hFile, view_as<int>(iFrame.NewWeapon), sizeof(FrameInfo), 4);
		ReadFile(hFile, iFrame.PlayerSubtype, sizeof(FrameInfo), 4);
		ReadFile(hFile, iFrame.PlayerSeed, sizeof(FrameInfo), 4);
		ReadFile(hFile, iFrame.AdditionalFields, sizeof(FrameInfo), 4);
		ReadFile(hFile, iFrame.Pause, sizeof(FrameInfo), 4);
		PushArrayArray(hRecordFrames, iFrame, sizeof(FrameInfo));
Quote:
Originally Posted by BEFORE
Code:
enum FrameInfo
{
	playerButtons = 0,
	playerImpulse,
	Float:actualVelocity[3],
	Float:predictedVelocity[3],
	Float:predictedAngles[2],
	CSWeaponID:newWeapon,
	playerSubtype,
	playerSeed,
	additionalFields,
	pause,
}
Quote:
Originally Posted by AFTER
Code:
enum struct FrameInfo
{
	int PlayerButtons;
	int PlayerImpulse;
	float ActualVelocity[3];
	float PredictedVelocity[3];
	float PredictedAngles[2];
	CSWeaponID NewWeapon;
	int PlayerSubtype;
	int PlayerSeed;
	int AdditionalFields;
	int Pause;
}

Last edited by LeeStrong; 04-18-2020 at 07:01.
LeeStrong is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 04-18-2020 , 00:37   Re: Bot Mimic: Enum Structs (Invalid Handle)
Reply With Quote #2

ReadFile is int ReadFile(Handle hndl, int[] items, int num_items, int size). It reads the given number of things, each of the given size.

In your original code, you do ReadFile(hFile, iFrame, view_as<int>(FrameInfo), 4) which essentially says to read as many bytes as a FrameInfo is large.

In your changed code, you split it up to read each member one at a time, but you're not giving it the proper size of each. The obvious fix is to give it the right size for each. Off the top of my head, though, you can still use one ReadFile call since an enum struct is still really an array.
Fyren is offline
LeeStrong
AlliedModders Donor
Join Date: Nov 2015
Old 04-18-2020 , 04:50   Re: Bot Mimic: Enum Structs (Invalid Handle)
Reply With Quote #3

--Please remove--

Last edited by LeeStrong; 04-18-2020 at 07:01.
LeeStrong is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode