Win32 API Vector Problem in Callback

In the WndProc callback of my program, I do this to save a mouse click in the vector:

case WM_LBUTTONDOWN:
    point = new POINT();
    point->x = LOWORD (lParam);
    point->y = HIWORD (lParam);

    point_vector.push_back(point);

    InvalidateRect(hWnd, NULL, TRUE);
    break;

It compiles fine, but when it does, I get an access violation on push_back. Both "point" and "point_vector" are declared globally and appear to be valid in the debugger. If I declare them locally, no access violations. Why is this going to happen?

This is on VS10.

@ Martin Lovell Here's a call stack

msvcr100d.dll! operator delete (void * pUserData = 0xfefefefe) 52 + 0x3 ++     my_app.exe! std:: allocator:: deallocate (tagPOINT * * _Ptr = 0xfefefefe, unsigned int formal = 0) 182 + 0x9 ++     my_app.exe! std::vector > :: reserve (unsigned int _Count = 1) 768 ++     my_app.exe! std::vector > :: _ (unsigned int _Count = 1) 1298 ++     my_app.exe! std::vector > :: push_back (tagPOINT * const _Val = 0x008e9d58) 992 ++     my_app.exe! WndProc (HWND * hWnd = 0x000b060a, unsigned int message = 513, unsigned int wParam = 1, long lParam = 19857987) 241 ++     774662fa() user32.dll!
    [ / , , user32.dll]
    user32.dll! 77466d3a()
    user32.dll! 77466ce9()
    user32.dll! 77466e44()
    user32.dll! 774677c4()
    user32.dll! 7746788a()
    my_app.exe! wWinMain (HINSTANCE__ * hInstance = 0x00c80000, HINSTANCE__ * hPrevInstance = 0x00000000, wchar_t * lpCmdLine = 0x006c35d2, int nCmdShow = 1) 62 + 0xc ++     my_app.exe! __ tmainCRTStartup() 547 + 0x2c C     my_app.exe! wWinMainCRTStartup() 371 C     kernel32.dll! 764c33ca()
    ntdll.dll! 77e79ed2()
    ntdll.dll! 77e79ea5()

, dbgdel.cpp( , ) /* type */ _ASSERTE (_BLOCK_TYPE_IS_VALID (pHead- > nBlockUse));

@CoreyStup , , vars

, , resize(), clear() reserve(), size().

+3
2

, . :

_stprintf_s(msgbuf, 1024, _T("Mouse coordinates: %d %d\0"), mouse.x, mouse.y);

_stprintf_s(msgbuf, sizeof(msgbuf), _T("Mouse coordinates: %d %d\0"), mouse.x, mouse.y);

, msgbuf!= 1024

.

0

"" "point_vector"... .

  • , , ? .
  • , " "?

:

6. msvcr100d.dll!operator delete(void * pUserData=0xfefefefe) Line 52 + 0x3 bytes C++
5. my_app.exe!std::allocator::deallocate(tagPOINT * * _Ptr=0xfefefefe, unsigned int formal=0) Line 182 + 0x9 bytes C++
4. my_app.exe!std::vector >::reserve(unsigned int _Count=1) Line 768 C++
3. my_app.exe!std::vector >::_Reserve(unsigned int _Count=1) Line 1298 C++
2. my_app.exe!std::vector >::push_back(tagPOINT * const & _Val=0x008e9d58) Line 992 C++
1. my_app.exe!WndProc(HWND * hWnd=0x000b060a, unsigned int message=513, unsigned int wParam=1, long lParam=19857987) Line 241 C++

:

1. my_app.exe!WndProc(HWND * hWnd=0x000b060a, unsigned int message=513, unsigned int wParam=1, long lParam=19857987) Line 241 C++

1 WM_LBUTTONDOWN WndProc.

2. my_app.exe!std::vector >::push_back(tagPOINT * const & _Val=0x008e9d58) Line 992 C++

2 push_back POINT .

3. my_app.exe!std::vector >::_Reserve(unsigned int _Count=1) Line 1298 C++

3 , push_back _Reserve 1, 1 POINT*. , , , 1. ( .)

4. my_app.exe!std::vector >::reserve(unsigned int _Count=1) Line 768 C++

4 , _Reserve .

5. my_app.exe!std::allocator::deallocate(tagPOINT * * _Ptr=0xfefefefe, unsigned int formal=0) Line 182 + 0x9 bytes C++

5 , POINT*, , ( VS 2010 _Myfirst) null (. _Ptr = 0xfefefefe ), , 0 (!) POINT*.

, allocator:: deallocate , 0 ( no-op) 0xfefefefe.

6. msvcr100d.dll!operator delete(void * pUserData=0xfefefefe) Line 52 + 0x3 bytes C++

6 , 0xfefefefe, , VS , . ?

  • 0xfefefefe?
  • push_back?
  • ?

.

+1
source

All Articles