r8320 - bugfix for "ai clear" crash

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

Message
Author
User avatar
ChrstphrR
Testers Team
Testers Team
Posts: 42
Joined: 09 May 2010, 17:30
Noob?: No
Location: Northern Alberta, Canada

r8320 - bugfix for "ai clear" crash

#1 Post by ChrstphrR »

This commit was added to prevent a crash from occuring when "ai clear" was used before openkore connected to the server.

Example crash dump errors.txt:

Code: Select all

OpenKore version what-will-become-2.1
Network state = 1
Network handler = Network::XKoreProxy
SVN revision: 8317
Loaded plugins:
  plugins/xconf.pl (xConf)
  plugins/macro.pl (macro)

Error message:
Attempt to STORE non blessed reference (or not a reference)
Value:
$VAR1 = {};

Stack trace:
Attempt to STORE non blessed reference (or not a reference)
Value:
$VAR1 = {};
 at src/Utils/BlessedRefTie.pm line 10
	Tie::BlessedRef::STORE('Tie::BlessedRef=SCALAR(0x43220e8)', 'HASH(0x44bcda8)') called at src/Commands.pm line 463
	Commands::cmdAI('ai', 'clear') called at src/Commands.pm line 294
	Commands::run('ai clear') called at src/functions.pl line 965
	main::parseInput('ai clear') called at src/functions.pl line 63
	main::mainLoop() called at src/Interface.pm line 75
	Interface::mainLoop('Interface::Console::Unix=HASH(0x2211be8)') called at ./openkore.pl line 97
	main::__start() called at ./openkore.pl line 187

Diff of r8320 - only src/Commands.pm affected.

The fix: simply wrap the undef for $char->{dead} with a check to see if $char is defined, first.

Code: Select all

Index: src/Commands.pm
===================================================================
--- src/Commands.pm	(revision 8317)
+++ src/Commands.pm	(working copy)
@@ -460,7 +460,11 @@
 		AI::clear;
 		$taskManager->stopAll() if defined $taskManager;
 		delete $ai_v{temp};
-		undef $char->{dead};
+		if ($char) {
+			undef $char->{dead};
+		}
 		message T("AI sequences cleared\n"), "success";
 
 	} elsif ($args eq 'print') {