Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

omegasyphon

directinput problem

This topic is 6227 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

when i go to run my program i get an unhandled exception from this line how would i correct this? when i debug, it goes to the GetDeviceState line.
    

int keycontrol(GLfloat x)
{

	HRESULT hr = lpdikey->GetDeviceState(sizeof(buffer),&buffer);

		if (KEYDOWN(buffer,DIK_ESCAPE))
		PostQuitMessage(0);
		if (KEYDOWN(buffer,DIK_LEFT))
			x -= .5f;
		if (KEYDOWN(buffer,DIK_RIGHT))
			x += 0.5f;

	return x;
}

}

  
Edited by - omegasyphon on June 26, 2001 4:10:46 PM

Share this post


Link to post
Share on other sites
Advertisement
u forst me to do this , mycode is pretty short tho

  
#define INITGUID
#include <windows.h>
#include <fstream.h>
#include <glut.h>
#include <stdio.h>
#include <math.h>
#include <objbase.h>
#include "dinput.h"
#include "vars.h"

#define glpi 3.1415f

GLfloat xrot,yrot;
GLint bx=0,by=0;
int mstate = 0;

LPDIRECTINPUTDEVICE7 lpdikey = NULL;
LPDIRECTINPUT7 lpdi = NULL;
UCHAR buffer[256];


HWND main_window_handle = NULL; // save the window handle

HINSTANCE main_instance = NULL; // globally track hinstance




int initcontrols()
{
if (DirectInputCreateEx(main_instance,DIRECTINPUT_VERSION,IID_IDirectInput7,(void**)&lpdi,NULL)!=DI_OK)
return 0;
if (lpdi->CreateDeviceEx(GUID_SysKeyboard,IID_IDirectInputDevice7,(void**)&lpdikey,NULL)!=DI_OK)
return 0;
if (lpdikey->SetCooperativeLevel(main_window_handle,DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)!=DI_OK)
return 0;
if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
return 0;
lpdikey->Acquire();
mstate=1;
return 1;
}

int keycontrol(GLfloat x)
{

if (lpdikey->GetDeviceState(256,buffer)!=DI_OK)
return 0;

if (buffer[DIK_ESCAPE] & 0x80)
PostQuitMessage(0);
if (buffer[DIK_LEFT] & 0x80)
x -= .5f;
if (buffer[DIK_RIGHT] & 0x80)
x += 0.5f;

return x;
}

int killkeyboard()
{
// first unacquire the mouse

lpdikey->Unacquire();

// now release the mouse

lpdikey->Release();

// release directinput

lpdi->Release();
return 1;
}

void renderscene()
{
GLfloat x;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glRotatef(x,1.0f,0.0f,0.0f);
glRotatef(30.0f,0.0f,0.0f,1.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,cords);
glDrawElements(GL_TRIANGLE_STRIP,1600,GL_UNSIGNED_INT,corners);
glPopMatrix();
glutSwapBuffers();
}

void setuprc()
{
glClearColor(0.0f,0.0f,0.0f,1.0f);
glColor3f(0.0f,1.0f,0.0f);
}

void ChangeSize(int w, int h)
{
GLfloat nRange = 100.0f;

// Prevent a divide by zero

if(h == 0)
h = 1;

// Set Viewport to window dimensions

glViewport(0, 0, w, h);

// Reset projection matrix stack

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Establish clipping volume (left, right, bottom, top, near, far)

if (w <= h)
glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
else
glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);

// Reset Model view matrix stack

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}


void main()
{
GLfloat x=0.0;
if (mstate==0)
initcontrols();
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("game engine console");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(renderscene);
setuprc();
keycontrol(x);
killkeyboard();
glutMainLoop();
}

Share this post


Link to post
Share on other sites
Is buffer created:

char buffer[256];

of char* buffer = new char[256] ?

If it is the latter then sizeof( buffer ) is gong to evaluate to the size of a pointer and not the size of your buffer.


Seeya
Krippy

Edited by - krippy2k on June 29, 2001 11:55:25 AM

Share this post


Link to post
Share on other sites
Are you positive that lpdikey is a valid DI pointer when you get to this code?

What does the exception say? Access violation?

Share this post


Link to post
Share on other sites
it just says unhandled exception error 0xc0000005
and goes to the line in game controls

if (lpdikey->GetDeviceState(256,buffer)!=DI_OK)

Share this post


Link to post
Share on other sites
Ok, 0xc0000005 is an access violation. It means that you are trying to access memory that you do not have permission to access.

Either lpdikey or buffer are not properly initialized before this call. I would be willing to bet that it is lpdikey. Post the code that you use to initialize lpdikey.

Seeya
Krippy

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!