TheSwamp

Code Red => .NET => Topic started by: TheMaster on November 21, 2012, 07:30:36 PM

Title: Anyone else get this?
Post by: TheMaster on November 21, 2012, 07:30:36 PM
Code - Text: [Select]
  1. Command: (setq a (cons 5020 -1))
  2. (5020 . -1)
  3. ; error: Exception occurred: 0xC0000005 (Access Violation)
  4.  
Title: Re: Anyone else get this?
Post by: Kerry on November 21, 2012, 07:44:35 PM

Yes
AutoCAD 2013  x64 Win 7 Pro
Title: Re: Anyone else get this?
Post by: TheMaster on November 21, 2012, 07:50:32 PM
 :roll:

Thanks
Title: Re: Anyone else get this?
Post by: Jeff_M on November 21, 2012, 08:09:02 PM
I, too, get this in C3D2012 x64 Win7 Pro
Title: Re: Anyone else get this?
Post by: TheMaster on November 21, 2012, 08:17:24 PM
Thanks.

And, how about this one?

Code - C#: [Select]
  1. namespace Namespace1
  2. {
  3.    public static class Class1
  4.    {
  5.       [LispFunction( "kaboom" )]
  6.       public static bool Kaboom( ResultBuffer args )
  7.       {
  8.          if( args == null )
  9.             return false;
  10.          TypedValue[] array = args.AsArray();
  11.          if( array.Length != 2 )
  12.             return false;
  13.          TypedValue a = array[0];
  14.          TypedValue b = array[1];
  15.          return a == b;
  16.       }
  17.    }
  18. }

Code - Text: [Select]
  1.  
  2.   Command: (kaboom nil nil)
  3.  
  4.  

[edit]

For anyone interested, the bug is triggered by the incorrect use of object.Equals( object ) within the TypedValue's overload of the == operator. It should be using object.Equals( object, object ), rather than the instance Equals( object) method, which of course, requires a non-null instance. You might note that while the managed runtime catches most exceptions thrown by calls to a LispFunction, NullReferenceException is not one of them.

You can avoid this problem by pre-processing TypedValues that come from LISP like so:

Code - C#: [Select]
  1. namespace Namespace1
  2. {
  3.    public static class MyExtensions
  4.    {
  5.        // call this in lieu of ResultBuffer.AsArray()
  6.        public static TypedValue[] ToArray( this ResultBuffer args )
  7.        {
  8.           if( args == null )
  9.              return new TypedValue[0];
  10.           return args.Cast<TypedValue>()
  11.              .Select( tv => object.Equals( tv.Value, null ) ? new TypedValue( tv.Value, Type.Missing ) : tv )
  12.              .ToArray();
  13.        }
  14.    }
  15. }
  16.  
Title: Re: Anyone else get this?
Post by: Gasty on November 21, 2012, 08:54:58 PM
Hi,


Tested on AutoCAD 2012 32 bits

(setq a (cons 5020 -1)) -> (5020 . -1)

(kaboom 2 3) -> nil
(kaboom 2 2) -> T
(kaboom '(1 2) '(1 2)) -> T
(kaboom '() '(1 2)) -> nil
(kaboom nil nil) -> ˇkaboom! (Fatal Error...)

Gaston Nunez
Title: Re: Anyone else get this?
Post by: TheMaster on November 21, 2012, 10:00:38 PM
Hi,


Tested on AutoCAD 2012 32 bits

(setq a (cons 5020 -1)) -> (5020 . -1)

(kaboom 2 3) -> nil
(kaboom 2 2) -> T
(kaboom '(1 2) '(1 2)) -> T
(kaboom '() '(1 2)) -> nil
(kaboom nil nil) -> ˇkaboom! (Fatal Error...)

Gaston Nunez

Gaston - Thanks.

Sorry, I forgot to include the LISP call that triggers it (kaboom nil nil), but I see you found it :laugh:
Title: Re: Anyone else get this?
Post by: Gasty on November 21, 2012, 10:37:32 PM
Hi Tony:

It happens I'm very good crashing AutoCAD, specially with my code :)

Very instructive example by the way.

Gaston Nunez