Go Back   RunUO - Ultima Online Emulation > RunUO > Core Modifications > Other

Other Cant find a category above, use this one! Core mods not listed above go here!

Reply
 
Thread Tools Display Modes
Old 07-11-2005, 04:17 PM   #1 (permalink)
Forum Novice
 
Join Date: Oct 2003
Location: Vienna, Austria
Age: 21
Posts: 127
Send a message via ICQ to Arahil
Default Point3D Comparison CrashBug-Fix

I already posted this in the Bugtracker, but since no one seems to care since about a month i'm posting it here again to prevent some of you from a Servercrash.

The problem is located in Point3D.operator ==(Point3D, IPoint3D) and Point3D.operator !=(Point3D, IPoint3D). It is never checked if the IPoint3D is null (to be honest - it seems to me that method is just copied from the comparison Point3D-Point3D, which can't be null, since it is a value type).


The fix for that is pretty simple - just a check if the IPoint3D-value is null:
Code:
public static bool operator == ( Point3D l, IPoint3D r )
{
	if (r == null) return false;
	return l.m_X == r.X && l.m_Y == r.Y && l.m_Z == r.Z;
}

public static bool operator != ( Point3D l, IPoint3D r )
{
	if (r == null) return false;
	return l.m_X != r.X || l.m_Y != r.Y || l.m_Z != r.Z;
}
Arahil is offline   Reply With Quote
Old 07-11-2005, 05:33 PM   #2 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

I assume this requires a core recompile.

Yes the code should have a null, but use of it shouldn't even involve a null. Its one of those things, you shouldn't do ( any code I can think of, makes sure it would't happen ).
Phantom is offline   Reply With Quote
Old 07-11-2005, 07:35 PM   #3 (permalink)
Forum Expert
 
Ohms_Law's Avatar
 
Join Date: Sep 2004
Age: 37
Posts: 1,006
Default

by adding the code that way, you'd never know if the comparisons (either way) were actually false, or if the code that was used to call it is simply malformed. what Phantom is (sorta) saying is that with base functions like this, you've gotta put the error checking onus on the code that calls the function.

think about this, you've got two basic values (number, letters, whatever). you wish to test if there equal or not. simple enough:
"if the value of A is equal to the value of B, do this"
where does the error checking go? to me, it shouldn't occur within that statement, but before that statement. so, instead of this:
"if the value that is in A is not null, then If the Value of A is equal to the value of what is in B, as long as B isn't a null value, do this"

doesn't it make more sence to do this:
"if the value of A is null, go get A"
"if the value of B is null, go get B"
"if the value of A is equal to the value of B, do this"
Ohms_Law is offline   Reply With Quote
Old 07-11-2005, 11:31 PM   #4 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Quote:
by adding the code that way, you'd never know if the comparisons (either way) were actually false, or if the code that was used to call it is simply malformed. what Phantom is (sorta) saying is that with base functions like this, you've gotta put the error checking onus on the code that calls the function.
You got the general idea, what I really said was, if you were going to compare to Point3D variables, you would know if they were null or not ;-)
Phantom is offline   Reply With Quote
Old 07-11-2005, 11:44 PM   #5 (permalink)
Forum Expert
 
Ohms_Law's Avatar
 
Join Date: Sep 2004
Age: 37
Posts: 1,006
Default

heh, yea
hey, I did end up saying that... in a round about way. lol
Ohms_Law is offline   Reply With Quote
Old 07-12-2005, 02:01 AM   #6 (permalink)
Forum Novice
 
Join Date: Oct 2003
Location: Vienna, Austria
Age: 21
Posts: 127
Send a message via ICQ to Arahil
Default

Quote:
Originally Posted by Phantom
I assume this requires a core recompile.
that's why it is in the core mod forum ^^


Quote:
by adding the code that way, you'd never know if the comparisons (either way) were actually false, or if the code that was used to call it is simply malformed. what Phantom is (sorta) saying is that with base functions like this, you've gotta put the error checking onus on the code that calls the function.

think about this, you've got two basic values (number, letters, whatever). you wish to test if there equal or not. simple enough:
"if the value of A is equal to the value of B, do this"
where does the error checking go? to me, it shouldn't occur within that statement, but before that statement. so, instead of this:
"if the value that is in A is not null, then If the Value of A is equal to the value of what is in B, as long as B isn't a null value, do this"

doesn't it make more sence to do this:
"if the value of A is null, go get A"
"if the value of B is null, go get B"
"if the value of A is equal to the value of B, do this"
i hope i got the point out of this ... umm... quite confusing text.
yes, you are right
but nevertheless, if you forget to check your values before you call the function (resp. the IPoint3D value, since Point3D can't be null anyway) your server crashes. i can't fix someones coding skills, i just can make sure he does not crash the server
Arahil is offline   Reply With Quote
Old 07-12-2005, 02:10 AM   #7 (permalink)
Forum Expert
 
Ohms_Law's Avatar
 
Join Date: Sep 2004
Age: 37
Posts: 1,006
Default

Quote:
Originally Posted by Arahil
i hope i got the point out of this ... umm... quite confusing text.
yea, sorry...
I suck as a teacher.

Quote:
i can't fix someones coding skills, i just can make sure he does not crash the server
that being said, education fixes everything. hehe
Ohms_Law is offline   Reply With Quote
Old 07-16-2005, 05:32 PM   #8 (permalink)
Forum Expert
 
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
Default

thats unnecessasy, the only way a get a null IPoint3D, to cast expilicitly something else as IPoint3D.

that means: unless you do something wrong, you dont get a null pointer exception..

but if you do, it is better to get that exception to debug..
noobie is offline   Reply With Quote
Old 07-16-2005, 05:35 PM   #9 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Quote:
Originally Posted by noobie
thats unnecessasy, the only way a get a null IPoint3D, to cast expilicitly something else as IPoint3D.

that means: unless you do something wrong, you dont get a null pointer exception..

but if you do, it is better to get that exception to debug..
Which was one of my points, the only way to get a null Point3D is if you pass it to the argument.

If you do that, then its your fault as a programmer.
Phantom is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5