Author Topic: Anyone else get this?  (Read 1674 times)

0 Members and 1 Guest are viewing this topic.

TheMaster

  • Guest
Anyone else get this?
« 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.  

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Anyone else get this?
« Reply #1 on: November 21, 2012, 07:44:35 PM »

Yes
AutoCAD 2013  x64 Win 7 Pro
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

TheMaster

  • Guest
Re: Anyone else get this?
« Reply #2 on: November 21, 2012, 07:50:32 PM »
 :roll:

Thanks

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: Anyone else get this?
« Reply #3 on: November 21, 2012, 08:09:02 PM »
I, too, get this in C3D2012 x64 Win7 Pro

TheMaster

  • Guest
Re: Anyone else get this?
« Reply #4 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.  
« Last Edit: November 21, 2012, 10:20:34 PM by TT »

Gasty

  • Newt
  • Posts: 90
Re: Anyone else get this?
« Reply #5 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

TheMaster

  • Guest
Re: Anyone else get this?
« Reply #6 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:

Gasty

  • Newt
  • Posts: 90
Re: Anyone else get this?
« Reply #7 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