VMWare Workstation 6.0 beta is available

VMWare started a beta program for its Workstation 6.0 product. I have to say that I find Workstation as a must have product - one that you can't live without, at least I can't. IMO it is the best workstation virtualization product out there (running on Windows), leaving [MS] VirtualPC far behind. Years away. Anyway, here is 6.0 beta which brings very useful features. My favorite being:

"Integrated Virtual Debugger - Workstation integrates with Visual Studio and Eclipse so you can deploy, run, and debug programs in a VM directly from your preferred IDE"

Isn't that just lovely?

There are other cool features coming, too: official support for Vista, multiple monitor display, automation APIs (I wonder whether this will be integrated into PowerShell) and headless mode. Plus there is broader support for devices, I think (USB 2.0, etc).

I see that VMWare Workstation is going to be even more indispensable. Right now I am downloading beta and hopefully will soon test the new features.

Sql Server 2005 Compact Edition released

Apparently [MS] is giving gifts away even before Christmas. Seems like Sql Server 2005 Compact Edition has been released, too. I say seems because download page is down, just like (VS2005 SP1 Update For Vista) Beta is (I've put parentheses in place to distinguish the meaning of Beta).

If you don't know what Compact Editions is then you should know that this is a free, copy & paste single user stripped down Sql Server 2005 version - perfect for storing data of single user (PC, smart phone, PocketPC, tablet PC) applications. The biggest plus is that it doesn't require any installation, just include proper assemblies and that's it. Forget DLL Hell (Access anybody?), complicated setup scenarios (MSDE anybody) etc.

UPDATE 19.12.2006: Link to download page now says RC1 but it still doesn't work.

Visual Studio 2005 Service Pack 1 (SP1) is here

Visual Studio 2005 Service Pack 1 has been released. Get it here. Note that if you are installing the thing on Vista you should explicitly use "Run As Administrator" assuming UAC is turned on (yes, I am back on UAC). Yet, it doesn't work for me. Perhaps there is a problem with SP1 beta which I installed before?

BTW, Isn't this a perfect descriptive message?

There is also a link to Visual Studio 2005 SP1 Update for Windows Vista Beta (I guess the update is beta and not for Vista Beta) but it isn't yet functional.

UPDATE (16.12.2006): Yes, it was SP1 beta. Andrej has posted SP1 beta uninstall instructions here.

Avoid using BaseEffect.SetValue(string, *) method overload in managed DirectX

I just found (the hard way) a nasty bug in managed DirectX (all versions I think). Why nasty? Because it happens more or less randomly after certain amount of time (2-10hrs) on some computers and it doesn't say much when exception is thrown (Invalid call or something). So, where is the problem?

Imagine you have a shader Effect defined somewhere in your code and you set its properties via SetValue method using string as a parameter name:

Effect someEffect = ... someEffect.SetValue("SomeEffectParameter", someValue);

Can you spot the problem? Of course not, neither could I. It is just the fact that application crashes randomly on SetValue invocation for no apparent reason. Granted, you have to call it many many times, but this is normal when using effects - you would set properties on every render pass.

Why does it crash? Good question, it took me quite a long time to find out - note that there was no good explanation plus a lengthy process to make it crash. I suspected hardware, graphic card driver and, of course, (managed) direct X. Having a faulty hardware is a possibility but you can pretty fast rule it out by switching hardware and re-test it. The problem was that crash was random so you couldn't be 100% sure. I 99% ruled out graphic card drivers by testing various versions. This is a very slim chance as gamers would notice problems in driver before you.

That leaves us with DirectX. Or better, Managed DirectX. I soon realized that the only chance to understand what's going on is by using Reflector. I first look at definition of SetValue method. It is a method of inherited BaseEffect class. It contains plenty of overloads (an overload per value type). The interesting fact that immediately drawn my attention is that no overload method accepts string as parameter name. Instead all methods do accept a EffectHandler class. How is it possible to pass a string instead then? EffectHandler implement = operator overloading that converts string to EffectHandle instance based on passed string. So far, so good. A look on EffectHandle implementation revealed that it consumes unmanaged memory. See where this is getting? Furthermore EffectHandle doesn't implement IDisposable thus you can't release unmanaged memory when you want (it implements a finalizer though). It is released if/when Garbage Collector's is in the mood of running in its finalizer - IOW randomly. But let's go back to EffectHandle's = operator overload. Here is what actually happens when you call SetValue with string argument as parameter name.

Implicitly, using = operator overloading, an instance of EffectHandle is crated for you and passed to SetValue. The reference to it is never stored and thus it becomes an orphan as soon as execution leaves SetValue method or even sooner. And within SetValue method it isn't disposed, simply because it can't be since it doesn't implement IDisposable, nor unmanaged memory released in any other way. It is left wandering in memory waiting for GC collection. So the pile keeps growing and GC doesn't even know that it consumes unmamanged memory (due to GC implementation in .net 1.1 - in .net 2.0 you can notify GC about how much unmanaged memory your instance uses - which is not implemented by EffectHandle in any way, too). After a while computer crashes...or not. Randomly, the worst developer's nightmare.

The workaround is actually pretty simple. Create proper EffectHandle instances for each property you need at effect's creation time and strictly use them for setting effect's parameters. Never ever use strings instead.

Here is proper code.

Effect someEffect = ... // both lines below should run only when effect is created EffectHandle someEffectParameter = "SomeEffectParameter"; // implicit creation EffectHandle someEffectParameter = EffectHandle.FromString("SomeEffectParameter"); // explicit creation - I preffer this one someEffect.SetValue(someEffectParameter, someValue);

Perhaps [MS] did never want us to use SetValue with string parameter. Not really, even Tom Miller suggested this approach in his Managed DirectX 9 Kick Start book. I think that not implementing IDisposable interface on a class that uses unmanaged code is a huge design error. Combined with not releasing that memory within SetValue is a wicked combination that should be fixed asap. Or not, since Managed DirectX is no more. I hope that people behind XNA, successor to Managed DirectX, are more careful.

Putting sleepless Vista to sleep

Since I have my new computer & Vista x86 I had problems with putting it into sleep or hibernate state - as soon it went to sleep/hibernate state it would wake up immediately and return to happy working mode (like my children - putting them to sleep is always an adventure). The motherboard is Intel based Gigabyte GA-965P-DS4 and it really shouldn't have problems. Thanks to the comment of PetarR I soon isolated the problem to Wake-On-Lan feature. For the test I disconnected computer from network (by pulling out the network cable) and it didn't wake up anymore until I didn't make him to. Good, but not good enough since I didn't know how to disable it (WOL was disabled in BIOS already) and I really didn't have time to play with it as the issue wasn't critical and I had a lot of other, more important, work to do. Fortunately Alex Feinman (.net CF MVP) suggested device manager's advanced features and that was it. I right clicked on my network adapter leaf

and turned off the only option that was "suspicious": Wake Up Capabilities (from Magic Packet & Pattern Matching to None).

And computer finally gets some sleep...

Interestingly, this device wasn't allowed to wake the computer even before.

Note that I am not yet on official drivers since Gigabyte didn't relase them yet.

PerfectDisk 8 runs on Vista

PerfectDisk 8, my favorite disk defragmentator, runs on Vista now. You really should run a disk defragmentaion once in while if you want your disk(s) to work at full speed. There is a Winodws built in disk defragmentation feature, however commercial ones, such as PerfectDisk 8, are much richer in features.