|
||
|
|||||||
| Other Cant find a category above, use this one! Core mods not listed above go here! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Forum Novice
|
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;
}
|
|
|
|
|
|
#3 (permalink) |
|
Forum Expert
Join Date: Sep 2004
Age: 37
Posts: 1,006
|
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" |
|
|
|
|
|
#4 (permalink) | |
|
Account Terminated
|
Quote:
|
|
|
|
|
|
|
#6 (permalink) | ||
|
Forum Novice
|
Quote:
Quote:
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 ![]() |
||
|
|
|
|
|
#7 (permalink) | ||
|
Forum Expert
Join Date: Sep 2004
Age: 37
Posts: 1,006
|
Quote:
I suck as a teacher. Quote:
|
||
|
|
|
|
|
#8 (permalink) |
|
Forum Expert
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
|
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.. |
|
|
|
|
|
#9 (permalink) | |
|
Account Terminated
|
Quote:
If you do that, then its your fault as a programmer. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|