LeapMotion SEHException

If for some reason when you try and run your code and you get a PINVOKE exception (like the one below), then most likely you don’t have the LeapMotion binaries in your Debug (or Release) folders.

System.TypeInitializationException was unhandled
Message=The type initializer for 'Leap.LeapPINVOKE' threw an exception.
at Leap.LeapPINVOKE.new_Listener()
at Leap.Listener..ctor()
at HelloLeap.MyListener..ctor()
at HelloLeap.Program.Main(String[] args) in c:\Users\amit.bahree\Documents\Visual Studio 2013\Projects\HelloLeap\HelloLeap\Program.cs:line 14
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.TypeInitializationException
Message=The type initializer for 'SWIGExceptionHelper' threw an exception.
at Leap.LeapPINVOKE.SWIGExceptionHelper..ctor()
at Leap.LeapPINVOKE..cctor()
InnerException: System.DllNotFoundException
Message=Unable to load DLL 'LeapCSharp': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Leap.LeapPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_Leap(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
at Leap.LeapPINVOKE.SWIGExceptionHelper..cctor()

On the other hand if you get a SEHException from LeapMotion (something like the one below) then the issue is either you don’t have the right version of the assemblies (e.g. you are compiling a x64 version, but have the x32 binaries, or vice-versa).

System.Runtime.InteropServices.SEHException occurred
Message=External component has thrown an exception.
at Leap.LeapPINVOKE.Controller_EnableGesture__SWIG_1(HandleRef jarg1, Int32 jarg2)
at Somewhere.In.Your.Code bin
at Some.Assembly in d:\Data\src\SomeCode\YourFile.cs:line 23

The solution is simple in both cases to copy the binaries (which can be found in LeapSDK\lib) to the Debug and Release folders.

Sleeves and LeapMotion

I have seen this a few times now so I know it is not a one off, but it seems that the sleeves of my shirt seem to throw off the Leap Motion sensor and it detects it as another hand – and ends up showing three hands.

I thought it was my watch which might be causing some issue, but that was not it. It goes away when I am wearing a t-shirt, but the tracking is quite off when wearing a full sleeve shirt.

I have been meaning to record a video, but not had a chance to do it yet. I was wondering, has anyone else also seen something similar?

Writing a compiler using C#

I was cleaning out my old papers (finally!) and came across an old paper I had titled “Compiler Writing Tools using C#” which essentially shows how you can write a number of tools like lex and yacc but instead of C/C++ on Unix, you use C# and .NET.

This paper covers the tokenizer, grammar, DFA, NFA, etc. I think conflicts and precedence is one area it would need a little more work. But overall its a very interesting piece of work – especially for one to learn the ropes if a lot of this is new.

Of course, writing compilers with C, overall is not the most productive experience (it sure is fun though!); if you have never done it before Standard ML or Haskell would be a better place to start. If you want to stick to .NET and roll out your own language (or create extensions) then check out this paper on MSDN.

All of this brought back memories when I wrote my own C++ compilers mainly with those tools on Unix System V and also on Xenix. Most people did not know (or perhaps remember) that Microsoft had a Unix version called Xenix which was later bought over by SCO and eventually become part of SCO Unix. Back in the days I use to run a dual-boot machine with Xenix and DOS. 🙂

Creating Word Maps / Word Clouds

I am giving a presentation next week on NoSQL and as part of that I wanted to create a Word Map, similar to the ones I have seen in the Guardian over the years. After searching a little, I came across the following two sites which do an excellent job of this. Both of them allow a number of options to customise the output and I think are very cool!

The first one is Jason Davies, World Cloud that is open source and you can integrate online searches, twitter searches, etc. The word map below is an example output when I search “bahree” on twitter.

The second one is Wordle, which is equally impressive but is a closed Java applet with some portions of the code copyrighted by IBM. With Wordle, you can enter some text, use a RSS feed or enter a del.icio.us user name to see their tags. I use my blog’s RSS feed to create the word map below.


A great example of a MANET

I have been doing some research on MANETs and UAV’s and this TED talk is a great example of how a number of nodes operate in a MANET and implement some predetermined algorithm, which in this case is the Bond Theme Song. Worth watching. 🙂

Kinect SDK

Microsoft recently release the Kinect SDK which allows you to implement a Natural User Interface and program against it! There is a lot of interest  around including claims on how Robotics will change to how you can integrate a light sensor.

You can use Visual Studio (C++, C# and VB.NET supported) and get quite interesting results.

Here are a series of links below which will help you get started.

  1. Download and install the Kinect SDK
  2. Download and install Quickstart Samples and Slides (zip file)
  3. Understanding the Kinect hardware
  4. Setting up your Dev Environment
  5. Understanding the basics of skeletal tracking using the Kinect sensor
  6. Understanding camera fundamentals
  7. Understanding the audio fundamentals
  8. Playing with the Coding4Fun Kinect toolkit and seeing how one can build cool apps such as:

Keep and eye out on the Coding4Fun Kinect blog.

Tips on Buying a UPS?

After moving to Bangalore, it turns out that I would need to get one or more UPS’s for the machines at home. The place we will be moving to in a few weeks does have power backup, but if/when there is a power cut it takes a few minutes for the generators to kick in and is not instantaneous as I was thinking.

I have never bought a UPS until now and don’t have any experience with it – what are the things that I need to consider? I will have the following equipment running which will need to be powered up for about 15 minutes:

  • 4 Desktops (including a MCE and WHS)
  • Two 17” LCD Monitors
  • A set of powered Speakers (optional)
  • Few switches
  • KVM Switch
  • VOIP Phone
  • Wireless Router
  • DSL Modem

Would it make sense to buy a few smaller UPS’s instead of one big one? Which is a good one? How much wattage/capacity should I look to get? Can one get second-hand ones – are they recommended? Does the UPS required any maintenance or are they maintenance free these days? 😕

Of all the machines, the WHS is one of the most critical ones. Is there any UPS’s which work well with some Add-Ins? I am interested in WHS shutting down in an orderly fashion so as to save all the data whenever the UPS battery gets low (in case for some reason the generators don’t kick in).

Upgrading through every version of Windows

Upgrading through *all* versions of Windows from v1 thru to Win7.

Opensource ZigBee stack?

I was planning on getting the Telegesis ETRX2USB and wanted to know if there are any open source (or shareware) open source ZigBee stacks that I can use with that?

I also wanted to know if there is any opensource (or not too expensive), network management or network analyser for a ZigBee network? Essentially I want to be able to programatically view network and node information on the ZigBee network (e.g. S/N ratio, signal strength, etc.) – something similar to Ember’s Insight Desktop which shows the details I am interested in. I could not find anything specific and would be interested in getting ideas.

Upgrading to WordPress 3.0.3?

The latest version of WordPress 3.0.3 and the Redirection plugin (v 2.2.3) don’t play nice together. If you upgraded to the latest version of WordPress the redirection plugin will always show only your last post on your blog’s homepage. Until the plugin is fixed, the only way around this is either not to upgrade to the latest version of WordPress (not recommended), or to disable the Redirection plugin.

Cray XMT

As you might have heard, the Cray XMT implemented a multithreaded processor architecture (called Threadstorm); these processors are compatible with Socket F which means they can use the AMD Opteron CPUs. The interesting part however is that these Threadstorm CPU’s only execute user code and avoids memory dependency stalls i.e. when the memory dependence prediction goes wrong and stalls the specific load to ensure there is no violation.

The Cray XMT does this by switching among 128 concurrent threads. As the XMT supports more than 8000 CPUs, if one needs to maximize throughput the developer must provide at least 128 threads per CPU, With 8K CPUs you are looking at over 1,024,000 threads! Surprised smile Needless to say, with such large number of threads, it is extremely important to get thread management implemented correctly – without that the system won’t be able to scale and even deadlock.

Another factor is the application design specifically the parallel programming models (including the recursive threaded models) and resource management to be able to successfully handle resource exhaustion.

If this is an area of interest then you should check out the likes of OpenMP, Parallel Extension to .NET 4 (which include PLINQ and TPL), CCR, etc.

Underpinning all of this of course is Amdahl’s law which one should be comfortable with; including its relation to the law of diminishing returns.

I wonder, where I can I get some time on a Cray XMT? I can also settle for a Cray CX1 – anyone willing to donate some money to a poor geek to help with this? Winking smile

Microsoft’s Street Slide

This is quite cool – now only if MS hurry’s up and incorporated this to Bing Maps.

MS Street Slide

Hardware Chart

This computer hardware chart is quite cool. Not sure why, where and who would want to use this. But, it does beg the question – can things get any geekier? 🙂


Analysis of Algorithms

If you were interested in algorithms and interested in some mathematical foundations for algorithm analysis? For example if you are interested in proof techniques, probability, Amortization analysis techniques, Case studies and Asymptotic notions (such as Big-Oh, Big-Omega, Little-oh, little-omega, Big-Theta) then check out these lecture notes (in ppt, 224kb) from California State University.

Ubuntu on a HTC Touch Pro 2

Well this is the phone I have maybe some day I will try this – pretty geeky albeit useless. 🙂

Geek moment of the day

(: ¿ɥǝ sıɥʇ sı looɔ ʍoɥ

Allowing remote desktop with blank passwords on Win7

I finally got the time to upgrade my MCE with the RTM bits of Win7 (was running an old RC build until now). Given this is a dedicated MCE with nothing else on it and an on an isolated part of the network, I don’t have a password set for the Account I use to login (of course not a recommended practice). Now, I wanted to RDP to the machine and I realised then that Win 7 does not allow RDP with blank passwords by default (Vista behaves in the same fashion). The workaround is a simple fix – to update the group policy as Dan shows in this post. Even though that post is for Vista, its the same steps for Win 7.

BizTalk Flat File schema optional attribute issue

I encountered this interesting issue and thanks to Colin we were able to resolve it. There will be situations you will encounter when adding additional optional attributes to a Flat File (FF) schema in BizTalk will cause problems. To get around this you basically will need to set the following properties to relax the parsing of the attributes which break.

  • parser_optimization="complexity"
  • allow_early_termination="true"
  • early_terminate_optional_fields="true"

This got me thinking more and wanting to understand what does changing these attributes mean under the covers. Below is what I found out on each of these.

On parser_optimization:

  • Setting the parser_optimization to complex essentially generates a more complicated grammar (it uses both a top down and bottom up parsing); this grammar is then used to parse the FF.
  • The complicated grammar is better when parsing records with more optional nested options – however it still cannot handle all the layout conditions and can still break in some situations.
  • And given the runtime is doing more things, this will be slower than the other option called ‘speed’ (yeah no kidding Sherlock!).
    • The reason the ‘speed’ option is faster is because it uses top-down parsing only.
  • In addition you should also set lookahead_depth to zero (more on this below) to avoid validation failures (against a schema) when there are many optional nodes in the same group/record.

Changing the lookahead_depth itself is trivial but you need to be a little more aware of what this means:

  • This essentially tells the parser when making a parsing prediction how far ahead to look in the token stream.
  • Setting this to Zero essentially means ‘infinite lookahead’ which in turn means more memory will be consumed.
    • Depending on how busy your BizTalk servers are and how much memory pressure you already experience processing various files (and their sizes), this might be an issue.

Basically, the FF parser is a streaming parser and implemented as a leftmost derivation which takes in a CFG. Essentially when we change the lookahead_depth to zero we change do not restrict this and the parser can recognize tokens using DFA perhaps (of course we don’t know the real implementation).

For those old school like me, and have played with yacc – that is a LL(1) parser – essentially parse the grammar with one token lookahead.

On allow_early_termination="true":

  • When working with FF’s BizTalk expects that every line is of the same length (either because of the data contained padded with spaces). However if it finds a newline (CR + LF) character then it breaks and you get an error something along the lines of “Unexpected data found while looking for: \r\n”.
  • Adding the allow_early_termination setting helps fix this. Read more here.
  • Also note that only the right-most positional field is allowed to early terminate.

Lastly, the early_terminate_optional_fields attribute enables early termination of optional trailing fields. A couple of points to note on this:

  • If your schema does not have this annotation and you open that in the BizTalk editor, then it will automatically add this annotation explicitly and set it to the default value of False.
  • This only takes affect if you also have the allow_early_termination annotation set to True.
  • More details on this here.

And in case you were wondering this is a supported option by Microsoft as shown in this KB article.