Raised This Month: $51 Target: $400
 12% 

INetworkStringTable crash?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 04-18-2005 , 21:41   INetworkStringTable crash?
Reply With Quote #1

Code:
CON_COMMAND(xtra_tablelist, "display network string tables")
{
	char *tablename;
	//int stringcnt;
	bool save = engine->LockNetworkStringTables(false);
	int NumberOfTables = networkstringtable->GetNumTables();
	int theTable = 0;
	INetworkStringTable *elTable = NULL;
	Msg("\nName\tStrings\n");
	while (theTable < NumberOfTables)
	{
		elTable = networkstringtable->GetTable(theTable);
		tablename = (char *)elTable->GetTableName();
		//stringcnt = elTable->GetNumStrings();
		if (tablename) {
			Msg(tablename);
			//Msg("\t");
			//Msg((char *)stringcnt);
			Msg("\n");
		}
		theTable++;
	}
	engine->LockNetworkStringTables(save);
	Msg("End of table names...\n");
}
CON_COMMAND(xtra_tablestrings, "display strings in specified table")
{
	const char *tablename = engine->Cmd_Argv(1);
	if (tablename) {
		bool save = engine->LockNetworkStringTables(false);
		INetworkStringTable *elTable = networkstringtable->FindTable(tablename);
		int NumberOfStrings = elTable->GetNumStrings();
		int theString = 0;
		char *buffa;
		sprintf(buffa,"All Strings for table \'%s\':\n",tablename);
		Msg(buffa);
		while (theString < NumberOfStrings) {
			Msg(elTable->GetString(theString));
			Msg("\n");
			theString++;
		}
		engine->LockNetworkStringTables(save);
		Msg("End of table names...\n");
	}
	else { Msg("No table specified. Use xtra_tablelist to get a list of string tables,\n"); }
}
Above are two commands I am using to view the INetworkStringTables and their strings. The xtra_tablelist command works fine, but when I use xtra_tablestrings on a table, it prints the strings then srcds crashes a few seconds afterwards. I have no clue why this happens, but I've been able to reproduce this error multiple times.
__________________
sslice is offline
BAILOPAN
Join Date: Jan 2004
Old 04-18-2005 , 21:43  
Reply With Quote #2

Clean up your code.

Code:
char *buffer;
sprintf(buffer..
Is totally invalid. You've got a garbage pointr and you're writing to it. Try:

Code:
char buffer[255];
...
...

Also... Msg() can work like Msg("%s", string);
__________________
egg
BAILOPAN is offline
BeetleFart
SourceMod Donor
Join Date: Apr 2004
Old 04-18-2005 , 21:49  
Reply With Quote #3

Quote:
Originally Posted by BAILOPAN
Clean up your code.

Code:
char *buffer;
sprintf(buffer..
Is totally invalid. You've got a garbage pointr and you're writing to it. Try:

Code:
char buffer[255];
...
...

Also... Msg() can work like Msg("%s", string);
and check pointers returned for non null cant hurt either

elTable = networkstringtable->GetTable(theTable);
if (elTable)
{

////code
}
__________________
CSource Server:
69.90.34.10:27015 Beetlesmod.com And CS-Addicts{US}



http://www.clanuseast.com
BeetleFart is offline
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 04-18-2005 , 21:58  
Reply With Quote #4

Works now.
Thank you both.
__________________
sslice is offline
Reply



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 11:19.


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