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!
http://members.harmonyremote.com/

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:
http://www.wired.com/reviews/2013/10/lg-g2/

Friday, August 2, 2013

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


<?xml version="1.0" encoding="utf-8"?>
<StepFilter xmlns="http://schemas.microsoft.com/vstudio/debugger/natstepfilter/2010">
 <Function><Name>boost::.*</Name><Action>NoStepInto</Action></Function>
 <Function><Name>std::.*</Name><Action>NoStepInto</Action></Function>
 <Function><Name>FMemory::Malloc</Name><Action>NoStepInto</Action></Function>
</StepFilter>

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:

Breakpoints
  • 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
Compilation
  • 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

#Fail

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

Installed...

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 :
&oList


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

Time...

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().

Friday, January 30, 2009

Now a PS3...

So now I got a PS3. Setup was pretty easy, but I still have major issues with its GUI.

Seems very old fashioned, very cluttered. On one hand it's nice to see the past menus you came from, but it just makes it look very busy.

Streaming with TVersity "just works". I love that it can play VOB files directly, whereas the 360 seems to have issues with them. It would be even more awesome if I enable subtitles from the VOB file (maybe it's not inside it)!

Blu-Ray and DVD playback is easier than the 360; I love that it can autoplay the movies when you turn the console on, whereas on the 360 you have to browse to the DVD or HD-DVD drive on My Xbox, then click on Play Movie.

It seems to run way hotter than my 360 for some reason, maybe the 360 has one of the newer chips that makes it run cooler?

I measured 106 degrees F inside the audio cabinet with the door closed, wow! (It accidentally stayed on when the cabinet door was closed...). I'm afraid to run this same test on the 360 :)

The only thing that really irritates me is that I can't play any PS2 games on it. Seriously, what's the deal with that?

I really hope Sony's working on a PS3 software emulator. There were so many games I almost bought for PS2, but thankfully I read the PS3's box... Not all of us had a PS2, Sony!

Wednesday, January 14, 2009

Don't eliminate the programmer...

I came across this very interesting post by Scot Westfall (SlickEdit's blog) "Eliminating the Programmer":

Here are some great points:
  • "[...]programmers have skills and abilities other than just their knowledge of programming languages."
  • "[...]Regardless, I’ve noticed that programmers are often more capable in many ways than their non-programming coworkers."
  • "Programmers think more logically. Working through if-then-else conditions is a core capability for any programmer. While working with business teams on requirements, I have often run across cases the where same ability was lacking."
  • "Programmers have a superior ability to analyze problems and come up with solutions. They excel at analyzing preconditions, sequences of events, and outcomes. Certainly, this is a key skill in programming, but it is also useful in troubleshooting and business case analysis."
  • "Another key ability where programmers typically have an edge is the ability to make order out of chaos. I think that’s because the programmer is responsible for creating order within the program."
  • "[...]their main talent lies in their ability to analyze, troubleshoot, and solve problems. Code is just the physical manifestation that culminates the thought process of the programmer."
Excellent insight into what being a programmer is all about.

Of course,
  • "it’s clear that this is not a universal trait in all programmers"
Read it in full, and enjoy!

Monday, December 15, 2008

XBox 360 & Verizon FiOS Networking adventures

As discussed before, I got a 360. So it was quite a bit of a pain getting this to work with my Verizon FiOS network connection, specially because paying $100 for a wireless adapter is kind of expensive, and my wireless signal's bad. Here's how thing are:

FiOS is the Verizon fiber optic service for internet/cable/TV/phone, etc that supplies my home with information and entertainment. The house is (as most of the houses on the US) wired for coaxial/cable all over, at least on each room.

The fiber optic from FiOS gets home from the street into my garage, where they have a hub which converts it to coaxial. This hub also has an ethernet output, which would be awesome and solve all my problems had the house be wired with ethernet. Anyways, so from this hub coaxial is conected to the house's wiring and that distributes it to the rooms.

My desktop is upstairs, and from the coaxial there's a so-called MoCA converter, which convertes coaxial to ethernet through Verizon's router, an Actiontec MI424WR. This is a wireless router too. So I plug my PC from there and use the wireless on the laptop downstairs and the Wii. Signal's pretty bad, too many walls in between (my house has a weird layout).

So the first thing I though is well, if I can get my DLink DI-524 as a wireless bridge, I can then just plug the 360 (which is downstairs too) directly into it and be done. So I looked at the DD-WRT project, but seems my DLink doesn't have enough on-board ram to be reflashed and reused as a bridge.

Just for kicks sake, I got a WRT54GL router and tried it with dd-wrt, and seems the Verizon router has issues with some routing table being too small. I also tried hooking up both the 54GL and the DLink's WLAN port into to the Verizon's LAN port, but that seems to kill the Verizon router.

After looking over pages and pages of info, I found this pretty useful one. So I would have to get new hardware...

Got on eBay and bought the same Actiontec router from Verizon for $20 bucks. Verizon wanted $150 for a new one. Crazy talk.

So days later I got the router.

So I looked at the previously mentioned report, double checked my equipment matched the diagram from the tutorial, and proceeded. I set the range of IPs for the 'main' router, the one where the 360 was hooked up, to 192.168.1.1 through 49, and set the static ip of the secondary (where the PC is connected) to 192.168.1.50, and the range of addresses to give from 51 to 99.

I got an IP for my PC of 192.168.1.51, which sounded good. I could ping the main router (1.1), and the secondary router (1.50). So far, so good!

Then I tried pinging www.yahoo.com, and... no cookie. Tried ipconfig /renew, tried changing settings and port forwarding for http and https ports in the verizon config for both routers, but still nothing.

So then I looked at my PC's ipconfig, and saw this:
IP: 192.168.1.51
Mask: 255.255.255.0
Gateway: 192.168.1.50

After some fiddling with it (and getting angry), I figured out that the gateway was the issue. So I went ahead and changed my PC's IP to be static (192.168.1.51) and forced the gateway to be the main router (192.168.1.1).

Everything works like a charm.

Not bad for somebody who slept through most of his computer networks classes ;)

XBox 360, WMP 11 & Streaming

So finally bit the bullet and got a 360. Just took me a few years to "jump in". What a wonderful piece of hardware! (Ignoring the three red rings of death issues). Getting used to hi-def console is hard, now I can see I might need a new prescription on my eyeglasses.

The new dashboard is nice, feels a lot more like the Wii channels but more 'professional'.

I can also now stream Netflix movies (using Netflix's own 360 downloaded app), PC audio, PC movies and my PC photos.

Which application I did that with?

The first thing I tried was Windows Media Player 11 from my laptop, which has Vista. (Why not the desktop? See a future post about networking woes). It just detected the 360 and the 360 detected the laptop, had to enter a code from the 360 and that's that, I could see/stream the files from the laptop to the 360.

However, I don't want the poor laptop's 160 GB drive being killed from streaming. Nor do I want the wireless connection's speed. I wanted the wired network to my desktop, where the big guns are.

So I tried WMP 11 on my desktop, but it just began to go nuts on my media files. Started changing attributes on my folder.jpg files, adding those AlbumArt*.jpg, and all sorts of crap.

I tried turning the options for WMP to now mess with my library but it just blissfully ignored me. So Google to the rescue!

I went with TVersity instead. Works like a charm! Doesn't mess up my files, streams with no visible CPU hit and monitors folders pretty nicely.

So now, I can get the kid's MP3 played on the 360, so she won't try to put her music CDs inside my home theater and/or dvd player and get them more scratched :)

Yet another reason to justify buying a 360. Hopefully the wife will buy it.

Wednesday, November 5, 2008

Keep it simple...

A colleague and I were discussing about which were the things that we learned from other programmers which made us better. I went on and on about how I learned to engineer software in baby-steps and how that helped me, but we ended up figuring out what makes great code robust and easy to use:

Keep it simple.

Not trying to over-engineer systems, not trying to hide things inside obfuscated APIs, basically not trying to look 'smart', and giving very simple pieces/components that have thin layers, will make you a better programmer.

If it is hard to explain, it probably is hard to mantain and expand.

At least on my experience, it has been a good rule of thumb. Specially now that I have it on my conscious mind :)

Wednesday, October 22, 2008

Still more STOP 0x00000024

I still can't track this down. My PC was up and running (and idle) for about 9 days, then suddenly it got the same STOP 0x00000024 error. I have Avast! as my antivirus, and Live FolderShare running all day, to sync files between work and home. And I played BioShock for several days in a row, no issues, exiting the game and saving correctly.

So I had to reinstall Windows on the IDE hard drive again, boot from that installation, which forces a chkdsk on the SATA drive, and then change the boot.ini file to boot on the SATA drive again.

chkdsk showed errors on a the files and folders I'm syncing with FolderShare, so that may be the culprit... Had to restore a bunch of them from backup.

I'm thinking it's a hard drive error, but the SeaTools suite keep telling me everything's good.

Tuesday, October 14, 2008

Black Textures on BioShock

So BioShock ROCKS. Ok, we know that.

Now for the issues...


I tried the demo back on my 6600GT AGP card a while ago, and figured it couldn't run (or look nice enough) with that card. So I uninstalled it.

Then I bought the retail version on my last upgrade, and had some issues with it.

I did some WinDbg debugging, some cleanup, chkdsks, etc and now the PC stopped crashing.

After a while, 30% of the game started showing with black textures, as if the lighting was messed up. Even worse, some characters (and bots/turrets) showed invisible textures, which made it very, VERY frustrating to play (I am walking happily, then suddenly I start getting my health all drained up. Guess what? Invisible enemy).

So I looked in forums all over, found nobody with my exact problem. Tweaked the hell of all the available .INI files in the games. Until I found a solution buried under a forum:

* Uninstall BioShock Retail
* Install BioShock Demo
* Uninstall BioShock Demo
* Install BioShock Retail

All's good now.

It's really perplexing since I did a full Windows Install after I first installed, so no traces of the BioShock demo would be there...