White Screen of Death

July 18th, 2007

I bought an Acer laptop last year. It seemed like a pretty good deal at the time. It was 1000$ cheaper than other. Though, I seemed to have got what I paid for. It promptly died in December, slightly before Christmas. I sent it back ($20) to them to get fixed and they said they replaced the mother board.

Since then, the screen turns white. It just fizzles out and turns completely white. This isn’t a software problem because it happens anytime, from the BIOS start screen, to inside XP. This was only a few weeks after I had got it back from being repaired. Sigh… So I sent it back again (another $20) to be fixed. Each time I sent it, its at least 2 weeks before I got it back.

Its been pretty good since then, until this week. It started turning white again. I only got it back a little over a month ago. Not again. So rather then send it back again (For another $20 and 2 weeks) I looked at what I could do.

Looking “White screen of death” up on the internet, showed that it could be problems with the LCD boards. I was lucky enough to find a repair manual for the laptop though. The manual showed some LCD parts above the keyboard. This looked like a good place to start. Since my screen was not almost permanently white, I figured it wouldn’t hurt to poke around.

After removing a cover, I had access to the connectors. After poking and wiggling a few of them, the screen came back. It seems the LCD cable is loose. Its not connected to the motherboard completely, and comes partially loose. Hmm.. seems someone didn’t put my computer back together quite that well after replacing the motherboard. As far as I can see though, the connection is tight and all the way in. It just isn’t staying in. Bad design?

Anywho, instead replacing a pricey inverter or back light or controller card for the LCD, it was just a partially loose connection. And to think, I could have sent it back to Acer to be fixed for another $20 and 2 weeks.

(Edit Dec 22 2007)

I notice a lot of people finding this page when searching for ‘acer white screen’.  From my findings, a white screen means that your LCD cable has partially loose.   Either take it into a shop to get fixed, or do it yourself.  To do it yourself, you probably need to open the top of your laptop above the keyboard.  Unplug the LCD connection and plug it back it, and secure it in place somehow.

Faster flash

May 2nd, 2007

I have been working on a project in Adobe flash for the last few months. It basically does a ton of animation and math on every screen. So i put all the code in onEnterFrame, the standard way to run continuous code, so it ran on each frame. Over the months I have done by best to optimize it for speed and efficiency but it had still ran slow, and used a lot of CPU power. How can I make it faster I thought?

The first most obvious thing to try was to up the FPS. Flash defaults it to 12, which seems rather slow for animation doesn’t it? So I updated it to 30, which didn’t seem the to change anything. 60fps offered a slight improvement. So it logically concludes that 120fps (the max you can set in flash) would give the best performance, and it seemed like it did. But the program was still using a ton of CPU power, and had a very low fps.

Was there a way i could squeeze a few more fps out of the program? Well there happens to be a function called updateAfterEvent() which basically tells the program to issue another screen refresh immediately. The only problem is that you can only call it from certain functions., one of which is NOT onEnterFrame. It would only work if called from an event, such as a mouse movement or key press. It also would work for a periodically ran function called through setInterval(). This looked like the option to try.

The function has this basic format:

setInterval(function, ms, params)

It takes a pointer to a function, the number of milliseconds in between calls to the function, and any params you would like to send it. That sounded wonderful, just set a really low ms, and pass in the function that does the same thing my current onEnterFrame does, and it should run as fast as I want. Well, not really. The one gotcha with this function is that it will only call the function at most, as often as onEnterFrame is called. The resolution of this timer is only as fine as the FPS in the movie. Even if i set the ms to 0, it would still only be called as often as onEnterFrame. Back the square one again, or was I? The new difference now was that I could call updateAfterEvent in the function, because it was called through setInterval. Yea! So i put the new code in, removed the old onEnterFrame, left out updateAfterEVents, set the ms to 10 and watched to see if there was any improvement.

Suddenly there was a 10x speed up. The animation wasn’t as sluggish and it responded to the uses key presses immediately. That didn’t make any sense. The same amount of code was being ran on every frame, the program should run the same speed. I tried changing the ms down to 1 and the animation only got faster. I changed the FPS of the program down to 12, and the animation was still just as smooth. I wondered if the function was being called more often the the screen updated, so I turned the FPS down to 1. A FPS of 1 resulted in jerky animation just as expected. So the function was still only being called as often as the screen updated. Turning the fps back to 12 (the default). I ran the program and watched the cpu usage, it was only around 10-20%, instead of the whopping 70% it was using before. Changing the FPS had the most effect on the CPU usage. A higher FPS resulted in more processor usage. But changing the MS in setInterval had barely any effect on CPU usage. Hmmm…. So i went around and changed all my onEnterFrame to setInterval code. This resulted in a much more responsive program, that had lower CPU usage. I still don’t know what the problem with putting code in onEnterFrame is, but I dont think I’ll be useing onEnterFrame much anymore.

The moral of the story:

DO NOT USE onEnterFrame in flash, its slow. Only use it if you absolutely must, but I don’t know why you would.
Changing the FPS does NOT result in faster code. Only MORE CPU usage.
USE setInterval(…) instead with a lowish FPS (such as 12)

Non-repeat random playlist in constant time?

January 13th, 2007

I’m sure you have all heard about the problems with certain mp3 players and their ‘random’ play lists. Some people think they repeat some songs more than others. Well here a way to get a truly random shuffle of the list in constant time. That means it takes the same amount of time no matter how big the list is.

This class takes takes an Array of items (data) and divides it into two sections. The first section is the already randomized items, the other is the items that haven’t been shuffled yet. When you request the next item, it picks a random item from the remaining set and swaps it onto the end of the shuffled set. When the non-shuffled set is empty, it starts from the beginning of the array again. At this point the whole array would have been shuffled already so no more swapping will be needed.
Here is the entire class in C#
class Shuffle
{
Random r = new Random();
Object[] data;

int split; // where the split is in the array
bool shuffled = false; // has the entire array been shuffled
public Shuffle(Object[] q)
{
split = 0;
data = q;
}

public Object Next()
{
if (split == data.Length)
{
split = 0;
shuffled = true;
}

if (!shuffled)
{
// find the next one
int idx = r.Next(data.Length – split);
// swap the positions
Object tmp = data[split];
data[split] = data[idx];
data[idx] = tmp;
}

return data[split++];
}
}This class shuffles the list in constant time. It only shuffles when a new item is requested from the list, and only shuffles that one item. This is many many times faster than shuffling all the items at once.

Enjoy.

Combination Generation

December 23rd, 2006

I ran across a wonderful article a while ago about a Combination / Permutation class that generated them as a stream.  It’s a great idea.  It makes unit testing pretty easy, as you can have the class make sure you hit all your test cases.  Sadly I wasn’t able to find the article again, at least I don’t think i was able to find it.

Anyway, I went a made my own combination generator.  For those wondering what a Combination is, its arranging K items from a set of N items, order doesn’t matter.  So given 5 items, and only taking 3 at a time you would get

0,1,2
0,1,3
0,1,4
0,2,3
0,2,4
0,3,4
1,2,3
1,2,4
1,3,4
2,3,4
The way this works is quite simple.  Each column has a min and max value that it can hold.  The first column goes from 0-2 (or 0 to (N-K) ), the last column goes from N-K to N-1.  You can easily generalize this into column C can hold a value from C to N-K+C.  The value of N-K can be precomputed.  Armed with this knowledge you can now make all your combinations.  First start with the identity (0,1,2,…,n).  To get the next combination, start at the right most item, and move left until you hit the first item that can be incremented, in other words, the value is between C and N-K+C.  Increment this value, then move back right and set each of these columns equal to 1 more than the item at its left (ie   c[i] = c[i-1]+1).

So given 0,3,4,  we start at the right (4).  4 is the max value for this column, so we move left.  3 is also the max value for this column, so we move left again.  0 is between 0 and 2, so we can still increment it.  We increment it to 1.  Now the array is 1,3,4.  Next we go back right and add set each column to one more than the column at its right, so we change the 3 into 1+1, which is 2.  We change the 4 into 2+1, which is 3.  This leaves us with the next combination of 1,2,3.

The last combination has the pattern of the first item equal to N-K (or 2 in our case).  When we reach this case we stop.

Ok, thats my little walk through on combinations. I’ll put something up about permutations next

n-jugs

November 9th, 2006

Given a set of n jugs of different sizes, how would you dump water between them to get a specific amount? If you have ever watched Diehard III, you might have seen this with 2 jugs. In the movie they are given 4 and 5 gallon jugs and are asked to make 3 gallons.

I originally tried to write a program to solve this problem using a brute force method. Needless to say, this was very slow and almost never ran to completion. I thought about it for a while and finally figured it out. It boils down to just solving a graph of connected nodes. Since I wanted to learn ruby, I used this to learn the language.

The basic idea to solve this is:

Have we reach the end state (desired amount)?
Loop through each from jug (i)
Loop through each to jug (j)
Calculate the new state of the jugs (water level in each)
Have we seen this “state” before? If not, store the new state. If we have, then move on
If this is a new state, go to step 1 with new state
old state, continue looping

Obviously, this wont find the optimal solution, but it will find a solution. If you want to find the optimal, you will have to store the steps to get to a state, and see if you have found a quicker path to a state. If you want, I still have the ruby file to solve this.