Dan:
I looked at the stack and it seemed to be fine. The _TCHAR vars are member variables for the class. Everything seems ok in the class. I changed the decl to
- Code:
_TCHAR *m_KeyNames[32];
and did a malloc(sizeof(_TCHAR)*((_tcslen(name)+1)) for each name and the problem went away. All of the keynames are less than 15, so I wasn't running out of room. The way I am doing it now uses less memory, but I hate using malloc.
Here is the code for the function that sets the keynames and appears to overwrite the member variable area and cause all of the problems. First part is the release build followed by the debug build. Debug build works, release does not.
Release Build
- Code:
00000 AREA |.text| { |?SetKey@cwKeyMap@@QAAXPAGK@Z| }, CODE, SELECTION=1 ; comdat noduplicate
00000 |?SetKey@cwKeyMap@@QAAXPAGK@Z| PROC ; cwKeyMap::SetKey
; 389 : {
00000 e92d4010 stmdb sp!, {r4, lr} ; stmfd
00004 |$M28698|
; 390 : _tcscpy(m_KeyNames[m_NumKeys],name);
00004 e3a03d66 mov r3, #0x66, 26 ; 0x1980 = 6528
00008 e3833018 orr r3, r3, #0x18 ; 0x18 = 24
0000c e1a04000 mov r4, r0
00010 e7b43003 ldr r3, [r4, +r3]!
00014 e3a02e91 mov r2, #0x91, 28 ; 0x910 = 2320
00018 e3822008 orr r2, r2, #8
0001c e0803383 add r3, r0, r3, lsl #7
00020 e0830002 add r0, r3, r2
00024 eb000000 bl wcscpy ; 0000002C
; 391 : // m_KeyCodes[m_NumKeys]=code;
; 392 : m_NumKeys++;
00028 e5943000 ldr r3, [r4]
0002c e2833001 add r3, r3, #1
00030 e5843000 str r3, [r4]
; 393 : }
00034 e8bd8010 ldmia sp!, {r4, pc} ; ldmfd
00038 |$M28699|
Debug Build
- Code:
01f3c AREA |.text|, CODE
01f3c |?SetKey@cwKeyMap@@QAAXPAGK@Z| PROC ; cwKeyMap::SetKey
; 389 : {
01f3c e1a0c00d mov r12, sp
01f40 e92d0007 stmdb sp!, {r0 - r2} ; stmfd
01f44 e92d5000 stmdb sp!, {r12, lr} ; stmfd
01f48 |$M28645|
; 390 : _tcscpy(m_KeyNames[m_NumKeys],name);
01f48 e59d100c ldr r1, [sp, #0xC] ; 0xC = 12
01f4c e59d3008 ldr r3, [sp, #8]
01f50 e3a02e91 mov r2, #0x91, 28 ; 0x910 = 2320
01f54 e3820008 orr r0, r2, #8
01f58 e083e000 add lr, r3, r0
01f5c e59d3008 ldr r3, [sp, #8]
01f60 e3a02d66 mov r2, #0x66, 26 ; 0x1980 = 6528
01f64 e3820018 orr r0, r2, #0x18 ; 0x18 = 24
01f68 e0833000 add r3, r3, r0
01f6c e5932000 ldr r2, [r3]
01f70 e1a00382 mov r0, r2, lsl #7
01f74 e08e0000 add r0, lr, r0
01f78 eb000000 bl wcscpy ; 00001F80
; 391 : m_KeyCodes[m_NumKeys]=code;
01f7c e59de008 ldr lr, [sp, #8]
01f80 e3a03c19 mov r3, #0x19, 24 ; 0x1900 = 6400
01f84 e3832018 orr r2, r3, #0x18 ; 0x18 = 24
01f88 e08e1002 add r1, lr, r2
01f8c e59d0008 ldr r0, [sp, #8]
01f90 e3a0ed66 mov lr, #0x66, 26 ; 0x1980 = 6528
01f94 e38e3018 orr r3, lr, #0x18 ; 0x18 = 24
01f98 e0802003 add r2, r0, r3
01f9c e5920000 ldr r0, [r2]
01fa0 e1a0e100 mov lr, r0, lsl #2
01fa4 e081300e add r3, r1, lr
01fa8 e59d2010 ldr r2, [sp, #0x10] ; 0x10 = 16
01fac e5832000 str r2, [r3]
; 392 : m_NumKeys++;
01fb0 e59d1008 ldr r1, [sp, #8]
01fb4 e3a00d66 mov r0, #0x66, 26 ; 0x1980 = 6528
01fb8 e380e018 orr lr, r0, #0x18 ; 0x18 = 24
01fbc e081300e add r3, r1, lr
01fc0 e5932000 ldr r2, [r3]
01fc4 e2821001 add r1, r2, #1
01fc8 e59d0008 ldr r0, [sp, #8]
01fcc e3a0ed66 mov lr, #0x66, 26 ; 0x1980 = 6528
01fd0 e38e3018 orr r3, lr, #0x18 ; 0x18 = 24
01fd4 e0802003 add r2, r0, r3
01fd8 e5821000 str r1, [r2]
; 393 : }