Assertion error on deleting object

Hello, i have a class called stInput that looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class stInput {
public:
	LPDIRECTINPUT8 din;
	LPDIRECTINPUTDEVICE8 dinkeyboard;
	BYTE keystate[256];
	bool Kill;


	void DetectKeyboardInput() {
		dinkeyboard->Acquire();
		dinkeyboard->GetDeviceState(256, (LPVOID)keystate);
	}
	void Work() {
		while (!Kill) {
			DetectKeyboardInput();
			if(keystate[DIK_LEFT])
				MessageBox(0, L"left", 0, MB_OK);



			Sleep(10);
		}
		Kill = false;
	}
	static DWORD WINAPI Worker(LPVOID ptr) {
		((stInput*)ptr) -> Work();
		return 0;
	}
	stInput::stInput(HINSTANCE hInstance, HWND hWnd) {
		DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&din, NULL);
		din->CreateDevice(GUID_SysKeyboard, &dinkeyboard, NULL);
		dinkeyboard->SetDataFormat(&c_dfDIKeyboard);
		dinkeyboard->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
		Kill = false;

		CreateThread(NULL, NULL, Worker, this, NULL, NULL);
	}
	stInput::~stInput() {
		dinkeyboard->Unacquire();
		din->Release();
		Kill = true;
		while (Kill) {}
	}


};


then when i call
stInput input (hInstance, EngInst.WindowHandle);
it starts up and works fine but when i call
delete &input;
i get assertion error, what does that mean?
Last edited on
Ok i discovered that if i handle the object like this
1
2
3
4
5
stInput* pInput = new stInput(hInstance, pEngInst->WindowHandle);

and

delete pInput;


it works fine. Why is that though?
Topic archived. No new replies allowed.