EDN Admin
Well-known member
Hi
I posted this question before in an Eigen library forum but it seems I may have hit a msvc 2010 compiler bug, so I post again here in hope you can give me some answers. If you know of a more relevant forum please let me know too:
post in Eigen forum: http://forum.kde.org/viewtopic.php?f=74&t=97995&sid=cd769a78f5b8b159239b9f032e2b7432 http://forum.kde.org/viewtopic.php?f=74&t=97995&sid=cd769a78f5b8b159239b9f032e2b7432
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px I have being wrestling for a few days with an inexplicable unhandled exception, access violation reading location xxx <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px At first I didnât suspect any relation with Eigen, and I still donât know whatâs happening but I think it involves
alignment of Eigen fixed size types in my particular context, so I post in here, luckily youâll have some clue to whatâs going on.<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px I have trimmed down my program to have an example with the smallest piece of code that has the elements that produce this access violation
reading. <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<dl style="font-size:13px; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; vertical-align:baseline; color:#222222; line-height:19px; padding:0px; margin:0px; border:1px solid #bbbbbb
<dt style="font-style:inherit; font-family:inherit; vertical-align:baseline; padding:0px; margin:0px; border:0px initial initial
Code: http://forum.kde.org/viewtopic.php?f=74&t=97995&sid=cd769a78f5b8b159239b9f032e2b7432# Select all </dt><dd style="font-style:inherit; font-family:inherit; vertical-align:baseline; background-color:#ffffff; padding:5px; margin:4px; border:0px initial initial
<code style="font-style:inherit; font-family:inherit; vertical-align:baseline; font:normal normal normal 1em/normal andale mono,lucida console,monospace; line-height:1.5; padding:0px; margin:0px; border:0px initial initial 1. class A<br/>
2. {<br/>
3. public:<br/>
4. A(int a):m_a(a){};<br/>
5. virtual int GetNumber(){return m_a;};<br/>
6. private:<br/>
7. int m_a;<br/>
8. };<br/>
9. <br/>
10. void test(shared_ptr<A> r)<br/>
11. {<br/>
12. try<br/>
13. { <br/>
14. throw std::runtime_error("Test exception");<br/>
15. }<br/>
16. catch(std::runtime_error &e) <br/>
17. { <br/>
18. cout << e.what() << endl;<br/>
19. }<br/>
20. <br/>
21. int i = r->GetNumber();<br/>
22. <br/>
23. Eigen::Vector4f saxy;<br/>
24. saxy << 1.0f, 0.0f, 0.0f, 0.0f;<br/>
25. }<br/>
26. <br/>
27. void main()<br/>
28. {<br/>
29. shared_ptr<A> APtr(new A(2));<br/>
30. test(APtr);<br/>
31. }<br/>
[/code]</dd></dl>
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px Iâm using Visual Studio C++ 2010 and Eigen 3.0.3. This code will run from begin to end in Debug mode, and release mode with optimizations
disabled. However, in Release mode with full optimizations enabled (/Ox) itâll produce this access violation at line 21. <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px If I change the Vector4f in line 23 to be Vector3f there wonât be an access violation at line 21. If I look at the assembly code
I see that when I use Vector4f there is some padding added at the beginning of the function test. <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px If I make A::GetNumber not virtual there wonât be access violation at line 21 either.<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px If I remove the try catch block there wonât be an access violation at line 21. <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px If I look at the stack in the debugger, just after coming out of the catch block, line 19, I can see that the stack is corrupted. Typically
there is some extra stack frame between main() and test(). <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px Unfortunately, I need all these elements in my original program, and despite meaningless I think this code should run without any problems???<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px Whatâs going on??? <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px Martin.
View the full article
I posted this question before in an Eigen library forum but it seems I may have hit a msvc 2010 compiler bug, so I post again here in hope you can give me some answers. If you know of a more relevant forum please let me know too:
post in Eigen forum: http://forum.kde.org/viewtopic.php?f=74&t=97995&sid=cd769a78f5b8b159239b9f032e2b7432 http://forum.kde.org/viewtopic.php?f=74&t=97995&sid=cd769a78f5b8b159239b9f032e2b7432
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px I have being wrestling for a few days with an inexplicable unhandled exception, access violation reading location xxx <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px At first I didnât suspect any relation with Eigen, and I still donât know whatâs happening but I think it involves
alignment of Eigen fixed size types in my particular context, so I post in here, luckily youâll have some clue to whatâs going on.<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px I have trimmed down my program to have an example with the smallest piece of code that has the elements that produce this access violation
reading. <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<dl style="font-size:13px; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; vertical-align:baseline; color:#222222; line-height:19px; padding:0px; margin:0px; border:1px solid #bbbbbb
<dt style="font-style:inherit; font-family:inherit; vertical-align:baseline; padding:0px; margin:0px; border:0px initial initial
Code: http://forum.kde.org/viewtopic.php?f=74&t=97995&sid=cd769a78f5b8b159239b9f032e2b7432# Select all </dt><dd style="font-style:inherit; font-family:inherit; vertical-align:baseline; background-color:#ffffff; padding:5px; margin:4px; border:0px initial initial
<code style="font-style:inherit; font-family:inherit; vertical-align:baseline; font:normal normal normal 1em/normal andale mono,lucida console,monospace; line-height:1.5; padding:0px; margin:0px; border:0px initial initial 1. class A<br/>
2. {<br/>
3. public:<br/>
4. A(int a):m_a(a){};<br/>
5. virtual int GetNumber(){return m_a;};<br/>
6. private:<br/>
7. int m_a;<br/>
8. };<br/>
9. <br/>
10. void test(shared_ptr<A> r)<br/>
11. {<br/>
12. try<br/>
13. { <br/>
14. throw std::runtime_error("Test exception");<br/>
15. }<br/>
16. catch(std::runtime_error &e) <br/>
17. { <br/>
18. cout << e.what() << endl;<br/>
19. }<br/>
20. <br/>
21. int i = r->GetNumber();<br/>
22. <br/>
23. Eigen::Vector4f saxy;<br/>
24. saxy << 1.0f, 0.0f, 0.0f, 0.0f;<br/>
25. }<br/>
26. <br/>
27. void main()<br/>
28. {<br/>
29. shared_ptr<A> APtr(new A(2));<br/>
30. test(APtr);<br/>
31. }<br/>
[/code]</dd></dl>
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px Iâm using Visual Studio C++ 2010 and Eigen 3.0.3. This code will run from begin to end in Debug mode, and release mode with optimizations
disabled. However, in Release mode with full optimizations enabled (/Ox) itâll produce this access violation at line 21. <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px If I change the Vector4f in line 23 to be Vector3f there wonât be an access violation at line 21. If I look at the assembly code
I see that when I use Vector4f there is some padding added at the beginning of the function test. <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px If I make A::GetNumber not virtual there wonât be access violation at line 21 either.<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px If I remove the try catch block there wonât be an access violation at line 21. <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px If I look at the stack in the debugger, just after coming out of the catch block, line 19, I can see that the stack is corrupted. Typically
there is some extra stack frame between main() and test(). <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px Unfortunately, I need all these elements in my original program, and despite meaningless I think this code should run without any problems???<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px Whatâs going on??? <br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<br style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px
<span style="color:#222222; font-family:Liberation Sans,Bitstream Vera Sans,sans-serif; font-size:13px; line-height:19px Martin.
View the full article