Jump to content


Member Since 28 May 2005
Offline Last Active Yesterday, 02:14 PM

Topics I've Started

C++: Union, struct and default constructor

28 July 2009 - 12:46 AM

Quick question regarding unions. I understand why a type I put in a union has to have a trivial default constructor. So my class definition is:
class MyClass {
      MyClass() {}
      MyClass(...) { /* other constructor */ }
Now when I declare a union like so:
union MyUnion {
   int numbers[4];
   MyClass instance;

my compiler (the one in Visual Studio 2005 SP1) complains that MyClass has a non-trivial default constructor. However, this compiles without problem:
union MyUnion {
   int numbers[4];
   struct {
      MyClass instance;

Can somebody enlighten me why this does work?

Test32Args fail when using /O2-flag

22 December 2008 - 08:44 AM

Some tests in the test_feature-directory fail for me when I use the /O2 (Optimize for Speed) flag in Visual Studio. The problem goes away when I use /O1 (Optimize for Size) or no optimization at all. This happens in both Angelscript 2.14.1 and 2.15.0. The failing tests are TestExecute32Args, TestExecute32MixedArgs and TestExecuteThis32MixedArgs. In case of TestExecute32MixedArgs, for example, I get:
TestExecute32Args (mixed arguments): testVal is not of expected value. Got:

ivalue[0]: 1
ivalue[1]: 2
ivalue[2]: 3
ivalue[3]: 4
fvalue[0]: 5.000000
fvalue[1]: 6.000000
fvalue[2]: 7.000000
fvalue[3]: 8.000000
ivalue[4]: 9
ivalue[5]: 10
ivalue[6]: 11
ivalue[7]: 12
fvalue[4]: 13.000000
fvalue[5]: 14.000000
fvalue[6]: -1.#IND00
fvalue[7]: -1.#IND00
ivalue[8]: 17
ivalue[9]: 18
ivalue[10]: 19
ivalue[11]: 20
fvalue[8]: 21.000000
fvalue[9]: 22.000000
fvalue[10]: 23.000000
fvalue[11]: 24.000000
ivalue[12]: 25
ivalue[13]: 26
ivalue[14]: 27
ivalue[15]: 28
fvalue[12]: 29.000000
fvalue[13]: 30.000000
fvalue[14]: 31.000000
fvalue[15]: 32.000000

The complete command line for the compiler is:
/O2 /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_WARNINGS" /D "_MBCS" /GF /FD /EHsc /MD /W3 /nologo /c /Wp64 /Zi /TP /errorReport:prompt
Hope you can reproduce, find and fix this problem. Thanks.

D3DX10ReflectShader on non-SP1 Vista

26 October 2008 - 01:34 AM

I'm making my first steps on using shader reflection in DX10. Now the docs say that I must use D3DX10ReflectShader, which will give me a pointer to a ID3D10ShaderReflection1. The 1 at the end leads me to believe it's a DirectX 10.1-structure, as does the remark in the documentation: 'This requires Windows Vista Service Pack 1'. So what happens when I use D3DX10ReflectShader on a Vista that does not have SP1? Can I simply cast the returned pointer to a ID3D10ShaderReflection, thereby maintaining DX 10.0 compatibility?

Bug in tokenizer on 64-bit?

06 March 2008 - 09:18 AM

I think I just ran into a bug in as_tokenizer.cpp. In line 118 (in 2.11.2), a loop is run on every character of the whitespace-string. The length of this string is determined by doing:
for( int w = 0; w < (int)sizeof(whiteSpace); w++ )

However, sizeof(whiteSpace) seems to give the size of the pointer to the string, which on 32-bit is 4 and incidentally correct. On 64-bit however, this becomes 8, which leads to all kinds of weird errors. Changing the line to
for( int w = 0; w < 4; w++ )

fixed these problems for me. [Edited by - DaBono on March 6, 2008 3:37:16 PM]

Determining Bezier-spline next to other spline

19 November 2007 - 01:21 AM

I'm looking for a method to calculate the control points of a Bezier-spline at a distance d from a Bezier-spline I have. So, say spline B describes the middle of a road, I want to determine the spline C that is the middle of one lane. This is in 2D, so I can calculate every point of C by determining the derivative of B at a certain t, finding the perpendicular (y, -x) and offsetting by my distance d. However, what I want is the control points. I thought I could do this by choosing to points on B (e.g. t=1/3, t=2/3), calculating the points on C with the method above, and then solving the Bezier-spline-equation with these points. However, it seems I cannot assume that the t of these points on C are 1/3 and 2/3 as well. Could somebody please point me in the right direction?