DLL problem and an Unhandled exception.

Apr 17, 2010 at 3:15 AM

I just downloaded this and followed along with the first video. I had two problems, one of which I self solved. Problem #1 (On windows 7), When I loaded the project in VS10 I got a cryptic System.NotSupportedException about loading DLLs from a network location. I had to right click all the DLL's in the download and choose "unblock" in order to make them work.


#2 and still unsolved I run the example I get the message "error on page". I loaded the example into VS10 and this is the error I get. I have both the SL3 and SL3 sdks installed.

 Microsoft JScript runtime error: Unhandled Error in Silverlight Application Index was outside the bounds of the array.   at Spritehand.FarseerHelper.BoundaryHelper.GetNextVertex(UIElement element, Point current, Point last, Double left, Double top, Double width, Double height, WriteableBitmap bitmap)
   at Spritehand.FarseerHelper.BoundaryHelper.GetPointsForImage(Image element, UIElement containerElement, Boolean positionOnly)
   at Spritehand.FarseerHelper.BoundaryHelper.GetPointsForElement(UIElement element, UIElement containerElement, Boolean positionOnly)
   at Spritehand.FarseerHelper.PhysicsSprite..ctor(PhysicsSimulator physicsSim, Canvas parentCanvas, UIElement element, List`1 points, Boolean showDebug, Single defaultFriction, UIElement boundaryElement)
   at Spritehand.FarseerHelper.PhysicsControllerMain.AddPhysicsBody(PhysicsObjectMain physObject)
   at Spritehand.PhysicsBehaviors.PhysicsObjectBehavior.controller_Initialized(Object source)
   at Spritehand.FarseerHelper.PhysicsControllerMain.InitializedHandler.Invoke(Object source)
   at Spritehand.FarseerHelper.PhysicsControllerMain.InitializeObjects()
   at Spritehand.FarseerHelper.PhysicsControllerMain._timerInitialize_Completed(Object sender, EventArgs e)
   at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)



This is my mainpage.xaml







































































 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:pb="clr-namespace:Spritehand.PhysicsBehaviors;assembly=Spritehand.PhysicsBehaviors"
 Width="640" Height="480">



 <Canvas x:Name="LayoutRoot" Height="600" Width="800" Background="Black">
   <pb:PhysicsControllerBehavior MousePickEnabled="True" DebugMode="True" GravityVertical="0"/>
  <Rectangle Fill="#FF444C5F" Stroke="Black" Height="79" Width="838" Canvas.Left="-17" Canvas.Top="537">
    <pb:PhysicsObjectBehavior IsStatic="True"/>
  <Image x:Name="image" Height="93" Width="127" Source="Ida.png" Stretch="Fill" RenderTransformOrigin="0.52,0.475" Canvas.Left="87" Canvas.Top="82">
    <pb:PhysicsObjectBehavior Mass="1" BoundaryElement="image"/>
  <Path x:Name="Ship" Fill="#FF444C5F" Stretch="Fill" Stroke="Black" Height="48" Width="57" UseLayoutRounding="False" Canvas.Left="305.5" Canvas.Top="143.5" Data="M306,158 L321,144 L343,152 L362,147 L339,191 L329,172 L310,168 z">
    <pb:PhysicsKeyTrigger Key="A">
     <pb:PhysicsApplyRotationBehavior x:Name="shiprotleft" RotateValue="-1"/>
    <pb:PhysicsKeyTrigger Key="D">
     <pb:PhysicsApplyRotationBehavior x:Name="shiprotright" RotateValue="1"/>
    <pb:PhysicsKeyTrigger Key="W">
     <pb:PhysicsApplyForceBehavior x:Name="shipthrust" ForceX="20" ForceY="20" ApplyForceEqualToRotation="True"/>






This is my MainPage.xaml.cs


using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Spritehand.FarseerHelper;
using FarseerGames.FarseerPhysics;


namespace FarseerTest
 public partial class MainPage : UserControl
  public MainPage()
   // Required to initialize variables


Apr 17, 2010 at 1:30 PM

It looks like the image you are using - Ida.png - is causing the issue. The physics helper is having problems determing the outline of the image.

Do you have the image included in your project, and is it appearing OK when you run?

Also make sure there are no "stray pixels" in the image (if this is the same image from the sample you should be ok, I wasn't sure what the image is?) Keep in mind that the helper uses an algorithm to "outline" any images by tracing a line around them - so if there are stray pixels it can throw it off.

Apr 19, 2010 at 6:44 PM

Thanks. I suspected that, and I cleaned up my image. I thought it was OK, but I must not have cleaned it up well enough. I cropped the image some more and it seems to be working now. Thanks.

This is a really neat tool by the way!