Wednesday, December 3, 2014

Windows changing size & position after monitor sleep

I recently updated my old 24" Dell monitor to a 32" Acer B326HUL, love it! But I found that when the monitor went to sleep, the windows got resized to a smaller res, as well as all the desktop icons got rearranged. Digging around on the internet found that Windows somehow remembered 1920x1200 as the res, and resizes all windows to fit that when coming out of sleep.

So the fix is registry magic!
In this register tree:

there is at least an entry per monitor; I had a DELxxxxxxxxxx and an ACRxxxxxxxxxx one, and under the 00 node, there are two parameters to check out there: and Stride.

These should match your current monitor.

A little below you should see these entries:

inside, you will also find under the 00 node, and those parameters pointing to the old sizes. Use the values from above, and also change under the remaining 00 node the & entries to match. Log off or restart and voila!


Thursday, July 17, 2014

Data breakpoints on Xcode

Keep forgetting about this!

watchpoint set expression address

Remove them:
watchpoint delete

Wednesday, July 16, 2014

Notepad++ Syntax highlighter for Metal, HLSL, Cg, etc

Based off Matt Pettineo's post, I've added support for half and also added Metal support:
Notepad++ User Defined XML

Though probably only Unreal users will/might develop Metal shaders on a PC :)


Tuesday, June 24, 2014

Lambdas instead of #define?

Recently I was running into this kind of code:
#define DUMPINFO(NameStatDumpInfo(NameStat)
#define DUMPINFO(NameStat)  /* Nothing */

void FunctionCalledALot()
 string InfoName;
 int InfoStat;

Which got my OCD up & running, as InfoName and InfoStat might not get removed (since the compiler might not figure out that GetInfo() has no side effects).

The typical way to solve this is to add the enclosing #define:

void FunctionCalledALot()
 string InfoName;
 int InfoStat;

The problems with this fix are:
a) DUMPINFO might have more conditions (like depending on a console variable)
b) Code rots: There might not be enough people enabling ONLY_WHEN_TRACKING_DOWN_BUG, which will cause the code to never get compiled, so changes to signatures or types will cause errors for the poor soul who tries to use it.

I was fiddling with this kind of solution, which I hope would fix those issues:
void FunctionCalledALot()
 auto DebugInfoLambda = [&]()
  string InfoName;
  int InfoStat;
  return std::make_tuple(InfoNameInfoStat);
I'm sure it has its drawbacks, but I think it solves the code rot issue, and the dead-code optimization issue too. So far the disassembly seems reasonable...

Friday, May 2, 2014

(Color) Basic

I think I was around 10 yrs old when I got my first personal computer. This was a TRS-80 Color Computer 3, which my grandparent bought in a Radio Shack. He put it on layaway and took us a full year to pay for it so we could bring it back to Mexico. I managed to sneak in a few game paks, Robocop, Super Pitfall and Thexder.
You hooked up the computer to your TV, turned it on and voila: Color-Basic!

10 PRINT "Hello"
20 PRINT "*"
30 GOTO 10

Something like that was my first program. The Color Basic manual was so great, and the language lent itself to exploration. LET is optional? You can add lines in the middle by using line number 15 if you missed anything? 320x192 at 16 colors!

After a while I managed to score a couple of the Rainbow magazine, and in there were new concepts: 6809 Assembly Language. You could do assembly inline using DATA, basically writing the opcodes yourself in Basic like:
20 DATA 254, 44

This involved writing the assembly language yourself, then finding out the opcodes and feeding them to the DATA instructions. Of course you'd mess one up and then all your program would get lost.

Did I mention I didn't have a save/load device? The Floppy Drive Kit costed more than the computer back then, and I tried a cassette tape but it would work only about 20% of the time, so I just ended up leaving the CoCo on, and every time I wanted to run a program I had to manually enter it.

My fondest memory is that one of the Rainbow magazines had a listing for plotting the Mandelbrot Set. It 'only' took about 15 minutes to enter the listing into the computer, then it would take *hours* to plot (you could see every pixel taking seconds). However the explanation in the article, as well as seeing the computer plot it one line at a time was magic.

EXEC 44539

Monday, March 31, 2014

Skip Visual Studio Debug Heap

Reminder: Set  _NO_DEBUG_HEAP=1 to disable using the crt debug heap.

Tuesday, January 14, 2014

Functional programming for Engineers

Being an Electronics & Computer Engineering major (not Computer Science), I missed out on the fun of functional programming. Having heard it's such a complete paradigm shift away from imperative programming, I had tried to teach myself Scheme, but didn't have a lot of motivation (for actual practical use).

Turns out that (while reading Alexandrescu's Modern C++ Design), template meta-programming is an excellent application! It's indeed a fun, different way of thinking (best for us used to dealing with assembly & C/C++ 99.9999% of the time!).

Just a month before, I was reading Andrew Koenig's Dr Dobbs series and this helped immensely to understand a bunch of concepts on this book. I highly recommend reading these series first, then digging into the book.

So run, don't walk to broaden your horizons!

Wednesday, December 18, 2013

Tip: iOS Memory Bug Fix

I kept hitting this crash over & over inside malloc (and there was still ~ 100 MB free):

mach_vm_map(size=*different size each time, < 1 MB*) failed (error code=3)
    *** error: can't allocate region
    *** set a breakpoint in malloc_error_break to debug

Turned out to be an issue on iOS 7.0 & 7.0.2; upgrading to 7.0.4 fixed it! Unfortunately the 7.0.4 release notes don't go into detail on which bugs were fixed.

Sunday, October 27, 2013

Logitech Harmony One Woes

Love my Harmony One; had to update the inputs since I rewired my TV, so tried getting the latest software, all fine and dandy until...

I updated.

Remote is now bricked! Goes straight into safe mode! Tried some things from the web: Drain battery, take out, wait a day and install, press OK while booting, press '2' while booting... Nothing.

I guess I had to reflash... Took me days to find the info, as using the provided software automatically updated to the new version, which keeps bricking the remote (goes into Safe mode always)!

Until I found: This is the website where you can reflash the firmware!

So happy my remote's back!

Monday, October 21, 2013

Upgraded my Galaxy Nexus...

Got an LG G2. Really nice phone!

+ Super fast & snappy, compared to achingly old Galaxy Nexus
+ Nice screen size, 5.2 but doesn't feel huge like a Galaxy Note
+ Battery lasts ~ 2 days, using Navigation+GPS, Wifi, Bluetooth, browsing, couple of games (my Galaxy Nexus dies after ~4 hours after using Nav+GPS with the extended battery).
+- Knock-knock feature works ~70% of the time
- Non-replaceable battery... Wonder when will it start giving out?
- 1920x1080, but seems that the software menu buttons kill off some, Epic Citadel said it was rendering at 1800x1080! Might also be affecting perf, as it averaged 37fps, it shoudl've been very close to 60 fps
- Not a lot of cases available :(
- Verizon changed the back buttons, so cases won't be compatible between AT&T/Verizon models
- Only black on Verizon

Wired review:

Friday, August 2, 2013

Visual Studio 2012 Tip: Skip stepping into function(s)

<?xml version="1.0" encoding="utf-8"?>
<StepFilter xmlns="">

Save it into:
C:\Users\USERNAME\Documents\Visual Studio 2012\Visualizers\SkipStuff.natstepfilter

Wednesday, December 12, 2012

Visual Studio Quick Tips

Very quick Visual Studio tips:

  • To put a breakpoint into any class methods, use Class::* as the breakpoint function
Watch Window
  • If you have your own type defined in autoexp.dat, you can use the ",!" modifier to skip it
  • $ENV=0 dumps the environment variables
  • $CMDLINE=0 dumps the command line
  • If you want a quick way to know the size/offset of your classes, add this compile flag to your cpp file (right-click on cpp file->Properties->Configuration Properties->C/C++->Command Line->Additional Options): /d1reportAllClassLayout

Friday, March 23, 2012

64 bit migration tips part 2

Pointer and structure padding: Fun times!

Consider a simple structure:
struct SStruct
  int m_nCount;
  int * m_pElements;
  int m_nMask;

In 32 bit land,
sizeof(SStruct) == 12;

In 64 bits:
sizeof(SStruct) == 20;

That's because m_pElements is a pointer, which is 8 bytes aligned, so now you have to remember to pad it out if you write it out as binary, or alternatively rejiggle the struct:

struct SStruct
  int * m_pElements;
  int m_nCount;
  int m_nMask;

Now in 64 bits:
sizeof(SStruct) == 16;

How can you write it from a 32 bit tool if you share the structure? Stay tuned...

Sunday, March 18, 2012

Migrating to 64 bits

Sooner or later you'll find at the crossroads of deciding whether or not switch to 64 bit. If you want to be future proof, do it!

Migrating our engine to 64 bit has been quite the ride. Here are some tips and recommendations:

* Make a new configuration off your 32 bit one. Then change the code generation to be x64.
* Temporarily remove all 3rd party libs linking with your project, and #ifdef the code that uses it out with some define. This is usually the most boring part; the goal here is to be able to compile/link first. We'll fix the runtime issues later.
* Once your solution links & compiles, try to run it for kick's sake. And start fixing the errors as you go.
* If you load binary data directly off disk, you'll have to work on each tool that generates binary data and make it work for 64 bit (or gasp! Both 32 & 64 bit!)
* The biggest issue we found during our conversion was pointers and padding. I'll discuss that in another post.
* You might be able to live with having 32 bit tools that generate 64 bit data. The usual problem with this is if you have a struct/class which you write out directly to disk, but there are ways around this.

Saturday, July 23, 2011

Droid X Freezing

So I started getting weird/random glitches on my Droid X, where the phone would just freeze. I could press the top button & turn off the screen, but when pressing it again or the home key to unlock, sometimes the bottom row of physical buttons would light up a bit and then turn off, or it would just not do that and keep the screen off.

Unfortunately I was out of the country so I had no internet or data access (I suspected it had to do with setting it in airplane mode for the first time), so I tried removing the SD card and voila! It stopped freezing.

But I could take no pictures, or read my kindle books offline (or play all the games in my sd card!) :(

Coming back I looked into this online and did the following:
1) Backup SD card to PC (worked!)
2) Format SD card from PC (worked!)
3) Copied some folders from backup to SD, put the card back into the phone, turn on and wait for hang...

So did 3) until I only missed the Music folder with all my MP3, and currently the phone works ok! I now have to go through all the files in the Music folder (about 6 gb) and check for weird issues...

So definitely a case of either a corrupt filesys or corrupt file (or an MP3 file with bad tags?).

Thursday, July 7, 2011


After spending quite some time trying to find a solution, gave up and asked stackoverflow...

Monday, January 24, 2011

Switching phones

Ok, I'm going from an old BlackBerry 8703e, to a Motorola DROID X Android Phone (Verizon Wireless), hopefully I'll see the Android Difference ;)

Tuesday, November 30, 2010

Finally here! Installation pics of my car stereo

It took a me a while to find the pictures of how the Sony MEX-BT3800U got installed in my Mitsubishi Endeavor, but here they are now!

Pull from the bottom left side a little bit:
 Now from the top right side:
Now from the top left:
At this point it has detached from the dashboard, and you can now pull from the top a little bit:
So far so good; now we have to remove that pair of screws you can see on the top, and with it we detach the cover of the clock/fm lcd:
You see those 2 black wires & the one with foam? Now if we look at this from the top, you can see they are attached to the grey metal cover, so manually unplug each one of them from the white plugs:
Ok, so after that, we can fully remove the grey panel!

Missing from this picture is the old stereo, which would be in the center slot; you'd proceed to remove the front 2 screws to take it out, and the ground cable.

To attach it back, follow the steps in reverse, and push it in the end towards the dashboard.

Disclaimer: You may burn your vehicle electronics! Detach at your own risk!

And the final product:

Wednesday, November 10, 2010

Saturday, August 14, 2010

Motherboard upgrade

Seems I've been getting a lot of random freezes on Win 7 x64; I'll blame it on the motherboard, a GA-P35-DS3L, so I'll be switching to a GA-EP45-UD3L instead. At this point who knows why it broke down...

Thursday, August 12, 2010

Waiting for Metroid...

I've got a preorder ready! Let's see what Team Ninja do with it!

Wednesday, July 7, 2010


I will take a nicer picture. This was taken quickly last night with my cell phone.

The cable you see there is the USB connector for the iPod.
I will be adding the external bluetooth microphone (so I have to tear it apart) so I'll be documenting that with (nicer) pictures :)

Friday, June 18, 2010

Mitsubishi Endeavor 2005 LS Aftermarket Stereo Installation

I wanted to have iPod support & bluetooth to my 05 Endeavor, but it seems the stock stereo has no way of hooking up an aux-in. I thought of getting a Garmin Nuvi 765T that has bluetooth & aux-in and use it on the fm radio... But I guess I figured I *could* install an aftermarket stereo all by my self (famous last words).

This was a pain to do! Seems all the online info is mostly for XLS owners which have the upgraded Infinity stereo system. I have the LS trim, so the option was to either make a new dash panel (yeah right, I can't even cut with scissors in a straight line!) or to use the lower pocket on the dashboard. That couldn't be too bad, could it?

In the end, success! I'll describe the issues I found and some pics...

Sunday, September 27, 2009

Showing std::vector in the debugger (continued)

Seems I found an even better way to show the container elements in the debugger: just add a watch for the address of the std::vector instance!

For example:
std::vector <> oList;
oList.push_back( -1 );
oList.push_back( 6 );
__asm int 3 /// Breakpoint here...

Add a watch for :

And it expands to (correctly sizing it!)
oList[ 0 ] = -1;
oList[ 1 ] = 6;

Friday, August 28, 2009

Showing std::vector elements in the debugger

Some std::vector instantiations do show up the members as arrays on Visual Studio 2005, some don't; if you need to access the member, you can use the following watch:

oYourVector._Myfirst[ nElement ]

Wednesday, June 17, 2009


Definitely the most valuable and scarce resource. It's hard (with a 2.5 year old toddler and a 1.5 month old baby) to have enough time to:
  • On DS: Play Exit, Picross and Etrian Odyssey
  • On PS3: Play Ninja Gaiden Sigma
  • On Wii: Play MadWorld and Punch-Out
  • On Xbox 360: Play Silent Hill 5, Gears of War, Condemned 2, Dead Space on Hard mode
  • Play Classical Guitar & Electric Guitar
  • Play Piano
  • Write an MP3 decoder/player from scratch
  • Write an HLSL optimizer/extender from scratch
  • Learn Scheme
But there will be time someday...

Thursday, April 16, 2009

Happy 15th Anniversary...

Super Metroid!

This nice piece on Gamasutra reminded me of it. I'm getting old! I 'borrowed' it from my friend's brother when I was 14... I think it mysteriously never got back to its original owner ;)

Tuesday, April 7, 2009

And Code Too...

Of course code also needs to be elegant, concise, clean, self-documenting and efficient.

My previous post was directed toward performance critical systems, those systems where you know it's the make-or-break 60 fps framerate...

Good class design (maybe even design patterns) is a characteristic of a good programmer. But maybe the best programmers can adapt and produce the right solution for a problem.

In other words, Empty your mind, be formless. Shapeless, like water. If you put water into a cup, it becomes the cup. You put water into a bottle and it becomes the bottle. You put it in a teapot it becomes the teapot. Now, water can flow or it can crash. Be water my friend.

So much to learn, so little time to do it...

Thursday, March 12, 2009

Not Code, but Data...

I've spent countless hours trying to come up with clean, elegant, concise and readable systems/APIs. Hours spent trying to see if a Design Pattern will help me, refactoring code, reading about best practices, etc.

But one day I had a Zen-like revelation.

It's not about the code, it's about the data!

See, all a computer/program does is transform and move data from one format to another. All we do when we try to come up with fancy interfaces are just ways for us humans to understand how the computer/program will transform the data.

Of course, you still need to program the APIs in a nice, clean, elegant and readable way, but keep in mind that the end product is just transforming/moving data. Streams of bits and bytes get split up, operated on, and joined into new streams of bits and bytes.

So in games programming/engineering, you need to figure out what data you need. Come up with a transformation function, and then clean up/refactor/humanize the code without losing performance.

I think that's the meat of games programming.

Tuesday, February 24, 2009

Shader tip

Tired of recompiling shaders all the time to try different combinations or code branches? Use this little hack in pseudo-code for selecting values: (I guess this was more useful on pre-shader model 3.0 hardware)

float4 g_vControl = float4( 1, 0, 0, 0 ); // Default to Branch1

float4 MainPS() : COLOR0
  float fValue0 = ResultFromBranch1();
  float fValue1 = ResultFromBranch2();
  float fValue2 = ResultFromBranch3();
  float fValue3 = ResultFromBranch4();
  float4 vValues = float4( fValue0, fValue1, fValue2, fValue3 );
  float fResult = dot( g_vControl, vValues );

// Do more math with the result...

Then on your main C#/C++ code, you can just set g_vControl to ( 1, 0, 0, 0) for Branch1, ( 0, 1, 0, 0 ) for Branch2, etc.

Of course, on release code you should remove this, or set g_vControl to be static bool so the compiler will optimize out the remaining branches. But for developing it's quite useful.

Also, you could blend the values: g_vControl = ( 0.5, 0, 0.5, 0 ) for example to blend Branch1() and Branch3().