Application Error 1005 Loading SSE DLL

While I was testing my latest release (1.2) of Vibratium I encountered a puzzling error. It took me a while to track this one down. Hopefully someone else can learn from this.

TL;DR: solution is at the end.

Problem:

Vibratium worked fine on my dev box, but on my laptop as soon as I added a Render Object the application would crash.

In the Application event log I got Application Error 1005:

“Windows cannot access the file for one of the following reasons: there is a problem with the network connection, the disk that the file is stored on, or the storage drivers installed on this computer; or the disk is missing. Windows closed the program Vibratium because of this error.”

Continue reading

Handling IDisposable Objects in a Generic List

I wanted to have more precise control over the lifetime of objects I was keeping in a list rather than wait for the GC. I came up with the code below which adds a few extension methods for handling IDisposable objects in a generic list. This was more elegant than adding a helper class.

I only implemented what I needed for the current project but these are very straightforward to do.

Sample code below.

using System;
using System.Collections.Generic;

namespace MyExtensions
{
    public static class Extensions
    {
        /// Remove tail, starting at index.
        public static void RemoveTail<T>(this List<T> list, int index)
        {
            if (index >= list.Count) { return; }

            if (typeof(IDisposable).IsAssignableFrom(typeof(T)))
            {
                List<T> temp = list.GetRange(index, list.Count - index);
                ClearAndDispose(temp);
            }
            list.RemoveRange(index, list.Count - index);
        }
        public static void ClearAndDispose<T>(this List<T> list)
        {
            if (typeof(IDisposable).IsAssignableFrom(typeof(T)))
            {
                foreach (T obj in list)
                {
                    IDisposable iFace = (IDisposable)obj;
                    iFace.Dispose();
                }
            }
            list.Clear();
        }
    } //*** Extensions
} //*** namespace

Usage is simple.

using MyExtensions;
...

var myList = new List<HugeObject>();
...

myList.RemoveTail(idx);
...

myList.ClearAndDispose();

SSELibrary 0.2 Available

SSELibrary 0.2 available for download. This version includes a much larger library of functions (149) with nearly full coverage of 8-bit operations, as well as enhanced CPU feature detection.

Details here: http://www.georgepotts.com/apps/sse-library/

WinForm Label Not Getting Focus

I have a user control that contains a few other controls, including Labels.  When any of the controls gets focus I want the parent to get notified.  I added an Enter event handler to the parent.  (Note: with Forms the equivalent to Enter/Leave is Activate/Deactivate.)  This almost works – any time I click on anything *except* the Labels the parent control gets focus.  After a bit of research I realized my error – Labels cannot receive focus, therefore the Enter event never fires despite it being there due to deriving from the Control class. (Enter and Leave events travel up the tree so all parents controls get notified.)

Stepping back, what I really want is that when I click anywhere on the control an Enter event is fired.

Continue reading