Archive

Archive for the ‘C/C++’ Category

warning C4541: ‘dynamic_cast’ used on polymorphic type ‘xyz’ with /GR-; unpredictable behavior may result

February 17th, 2011 No comments

I got this error today in Visual Studio when building our game at work.
I was trying to go a harmless dynamic_cast to downcast and object to a derived object and was confronted with this problem. After looking up the error it seems that it can be made to go away by turning on RTTI which is something we do not want to do due to the overhead of it and we have our own reflection system anyway and the type information isn’t required from RTTI. The reason being that dynamic_cast makes use of typeid which is only available under RTTI enabled projects.

I could have done a static_cast but didn’t want to do this blindly. Also not being a fan of ‘unpredictable behaviour’ I instead had to resort to a old fashioned dangerous C-style cast e.g.

     MyObject* pObj = (MyObject*)pObjectToCast;

This works fine, gets rid of the warning but I don’t like it.

Categories: C/C++ Tags:

Visual Studio – No files were found to look in. Find was stopped in progress.

December 13th, 2010 No comments

This is the weirdest thing, I was working away in Visual Studio 2008 when I attempted a global search and it failed indicating that ‘No files were found to look in. Find was stopped in progress.’. The weird thing is that I had selected Entire Solution and it should have worked. After some quick googling I found out that other people have had the same problem. Although the reason for it happening hasn’t been entirely explained (nor do I really care) the solution is as follows:

In VS2008 press Alt + Break to make find work again
In VS2005 press Ctrl + Scroll Lock (I haven’t tried this one)

Find works again, hurray!

Categories: C/C++ Tags:

Get Windows folder path

December 10th, 2010 No comments

It is quite easy to find a path to a particular folder in Windows, a function called SHGetFolderPath exists that will return you the user’s file system path to common system locations such as My Documents, Program Files, My Music, App Data and so on. I wanted to get the system font folder path so this function proved especially useful. Usage is as below:

Requirements: Add shell32.lib to your linked in libraries.

#include 
#include 

TCHAR strPath[ MAX_PATH ];

if (FAILED(SHGetSpecialFolderPath(
	0,       // Hwnd
	strPath, // String buffer.
	CSIDL_FONTS, // CSLID of folder
	FALSE ))) // Create if doesn't exists?
{
	//SOMETHING HAS GONE WRONG
}

Works a treat
WARNING: This function is supported from Windows 2000 Server onwards, if you need to support these OSes you may need to use something else.

Categories: C/C++ Tags:

PrintF wide format specifier

November 15th, 2010 No comments

Today I ran into the problem whereby printf was putting junk into a string even though it was using %s. A little perplexed about it I had a look around and saw that there is a separate format specifier that expects a wide string. My application is not compiled in Unicode but I require a wide string at this point.

So

wsprintf(buffer, L"Name %s", myWideCharString)

The above code wouldn’t work. However if I use the code below it would

wsprintf(buffer, L"Name %lS", myWideCharString)

The reason being that printf does some behind the scenes conversion and %s or %S will convert to a char*. %lS tells it that what is coming in is a wide string and to handle it as such.

I also found out that %f doesn’t work with wsprintfW, wierd and quite silly really.

Categories: C/C++ Tags:

Pure virtual functions error LNK2019

November 3rd, 2010 No comments

I ran into this error today when trying to refactor some code. Confused initially as LNK2019 means a function definition cannot be found. However the functions were defined in the derived classes so why the error?

The problem stemmed from the fact that my base class called the virtual functions in the constructor and destructor. Apparently the vtables aren’t available at this point for a class and so the compiler cannot resolve the call for a particular function. Hence the error.

The solution of course is to not call virtual functions from the constructor or destructor.

Categories: C/C++ Tags:

Football Superstars

September 25th, 2010 No comments

Hi all (if anyone actually reads this),

Well I’ve moved jobs (again). I’ve moved from Sony working on SingStar Dance to Cybersports world working on a football MMO called Football Superstars. The game has so much potential and with the team we have in place we can do some really exciting things with it. I promise to start blogging a little more – yes I know I’ve said that before!
My iPhone game, is getting close to final functionality I need to add in in-app purchases and a few other bits and I’ll be ready to unleash it out into the wild. That said I need to prettify it a bit more and sort out the downloads, maybe in a couple of months or so!

So…the Eddie Long scandal

September 25th, 2010 Comments off

Apparently I’ve been involved in a scandal. I must confess that whatever I did, I didn’t mean it.

Actuually I’m only kidding, I noticed the number of visits to my site have increased dramatically in the last week. Not really knowing why I noticed that my name is a trending topic on Twitter! It appears that my arch enemy Bishop Eddie Long (mostly as he is the top hit on Google ahead of me) has been involved in some sort of scandal. Sorry if you’ve come to my site by accident, I admit to attempting to drive traffic through with my cheeky blog posting title :)

Achieving smooth transparency and glowing

August 13th, 2010 No comments

Generally when you want something to flash on and off in a smooth fashion you have a duration that you want an icon to fade in and out at. You then tend to have a timer that increments up to the fade value and when it hits the fade value begins to decrement again down to zero. See the code below for an example of this in action

static const f32 totalFadeTime = 4.0

if (m_fadeUp)
{
	timer += delta;
	if (m_timer > m_revealTime)
	{
		timer = m_revealTime;
		m_fadeUp = false;
	}
}
else
{
	timer -= delta;
	if (timer < 0.0f)
	{
		timer = 0.0f;
		m_fadeUp = true;
	}
}

const f32 alpha = timer / totalFadeTime;

icon->SetAlpha(alpha);

The approach above uses linear interpolation so the fade looks quite even and bland. To get a nicer smooth fade you can use sin or cos alongside the linear value to give you a smoother looking effect. This is because of the curve of cos is not linear cos curve. Add the following lines to achieve this effect:

const f32 alpha = timer / totalFadeTime;
const f32 newAlpha = (cosf(TwoPi * alpha) - 1.0f) * -0.5f;
icon->SetAlpha(alpha);

Unfortunately I don’t have an example of this on hand to show but I does the trick nicely.

Categories: C/C++ Tags:

Just a test

July 31st, 2010 Comments off

testing FB and twitter posts

Categories: C/C++ Tags:

Tumbleweed

July 31st, 2010 No comments

It’s been quiet around here lately. I’m going to try to make an effort to blog here a bit more, it will mostly be about my SingStar coding experiences!

Categories: C/C++ Tags: