Crash when setting radius of PolyShape

Chipmunk2D Bindings for the Unity3D engine
Post Reply
Exploding Rabbit
Posts: 14
Joined: Wed Dec 04, 2013 3:31 am
Contact:

Crash when setting radius of PolyShape

Post by Exploding Rabbit »

If I set the radius of a ChipmunkPolyShape through a script, I get the following error and Unity freezes:

Code: Select all

ExecutionEngineException: SIGILL
ChipmunkPolyShape.set_radius (Single value) (at Assets/Plugins/Chipmunk2D/Shapes/ChipmunkPolyShape.cs:72)
ExplodingRabbit.CustomAssetModificationProcessor.OnWillSaveAssets (System.String[] paths) (at Assets/Scripts/File management/Editor/CustomAssetModificationProcessor.cs:25)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.AssetModificationProcessorInternal.OnWillSaveAssets (System.String[] assets, System.String[]& assetsThatShouldBeSaved, System.String[]& assetsThatShouldBeReverted, Int32 explicitlySaveScene)
If it matters, I'm calling it through an editor script. I have not tested in play mode.

It's worth noting that setting the radius of a ChipmunkSegmentShape through a script does not cause the same error. I have not tested with other shape types.

I am able to get around the bug by using ChipmunkPolyShape._radius instead. By the way, why are all of these fields with underscores public? It seems like they should be private or protected.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Crash when setting radius of PolyShape

Post by slembcke »

It's probably flat out dying on a NULL pointer for the shape. Internally the objects are in a completely different state when the editor vs. game is running since we can't instantiate native objects until they are added to the scene. We never really considered that the properties would be set in the editor. Unfortunately it would require adding editor checks to every single property to support that. All of the properties must be backed by a public* instance variable to show up in the editor, so you can always safely set those in editor scripts.

*That also answers your other question. Unless they added some new annotation to Unity recently to change it, variables that show up in the editor must be public. Adding the underscore is really the only way to mark it as something you probably don't want to set directly. Some members should have just been hidden away in a namespace, but Unity used to choke on them (in 2.x anyway). Apparently they fixed the compile issues in newer versions, but I didn't find out until we had mostly finished Chipmunk Unity.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Exploding Rabbit
Posts: 14
Joined: Wed Dec 04, 2013 3:31 am
Contact:

Re: Crash when setting radius of PolyShape

Post by Exploding Rabbit »

slembcke wrote:Unless they added some new annotation to Unity recently to change it, variables that show up in the editor must be public.
Use the SerializeField attribute to serialize a nonpublic field and make it show up in the editor.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Crash when setting radius of PolyShape

Post by slembcke »

!!!

Well that is really useful to know. The underscore prefix was recommended in the past as a workaround. Old habits die hard I guess. :-\
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests