Visual Studio 2010 Alignment Problems

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
User avatar
stealth977
Gnoll
Posts: 638
Joined: Mon Dec 15, 2008 6:14 pm
Location: Istanbul, Turkey
x 42

Visual Studio 2010 Alignment Problems

Post by stealth977 »

Today I spent an hour to solve an interesting issue, an exception that occurs when assigning a btVector3 to another btVector3 (bullet vector struct), which only happened in some random class but not all instances of the class.

After many debug traces, I decided to check if there was an alignment issue, and yes there was, somehow some of the btVector3s were aligned on 8 byte boundaries which should not happen since the struct has align(16) defined.

So, I dug the issue on the internet and found out that Visual Studio 2010 has a flaw that sometimes it can not resolve the correct alignment for class members even when explicit alignment options are defined. The issue is mostly related to DEBUG BUILDs and solved in Visual Studio 2013.

So, why do I share this? Because now OGRE 2.1 uses 16byte aligned SIMD types, some of you using visual studio 2010 may come across weird crashes and wanted you all know that it is a problem with Visual Studio 2010 alignment resolution...
Ismail TARIM
Ogitor - Ogre Scene Editor
WWW:http://www.ogitor.org
Repository: https://bitbucket.org/ogitor
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Visual Studio 2010 Alignment Problems

Post by c6burns »

This is a really good tip. When I switched to VS2013 from 2010 I suddenly became aware of all the possible alignment issues in my physics code and had to fix them before I hit a stumper of an issue such as this.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Visual Studio 2010 Alignment Problems

Post by jacmoe »

That begs the question: why are you guys using vs2010 and not vs2013? :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Visual Studio 2010 Alignment Problems

Post by c6burns »

I switched a few weeks after 2013 went free :P I was lucky to never not get bit by this alignment issue because 2013 screamed bloody murder where 2010 was asleep at the wheel.
User avatar
stealth977
Gnoll
Posts: 638
Joined: Mon Dec 15, 2008 6:14 pm
Location: Istanbul, Turkey
x 42

Re: Visual Studio 2010 Alignment Problems

Post by stealth977 »

I use VS 2010 because I own a VS2010 Professional. The point is we are doing open source code and can not really control which compiler the end user uses. I can write all code in 2013 and then will have to deal with crash reports from many users, crashes which I can not replicate on my machine...
Ismail TARIM
Ogitor - Ogre Scene Editor
WWW:http://www.ogitor.org
Repository: https://bitbucket.org/ogitor
Post Reply