Skip to main content
GameDev.net gamedev.net
🔒 Locked

sprite class declaration problems

Started by Malazar Apr 4, 2007 at 7:48 AM 2 replies 700+ views
Original Post
Malazar
Malazar
I'm using a series of sprites to create a GUI for a game i'm working on, however, when converting from a stand alone project to a C++ class i had trouble figuring our where the devices, textures, etc should be declared. it appeared the only way it would work is if they were declare them in my header file (named MenuButton.h) they are declaired as follows: LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; LPDIRECT3DTEXTURE9 g_pMenuTexture = NULL; LPD3DXSPRITE g_pMenuButtonSprite = NULL; however, i now get these errors, which, to me, make no sense - since this is the only place these variables are defined: TestMenu.obj : error LNK2005: "struct IDirect3DDevice9 * g_pd3dDevice" (?g_pd3dDevice@@3PAUIDirect3DDevice9@@A) already defined in MenuButton.obj TestMenu.obj : error LNK2005: "struct IDirect3DTexture9 * g_pMenuTexture" (?g_pMenuTexture@@3PAUIDirect3DTexture9@@A) already defined in MenuButton.obj TestMenu.obj : error LNK2005: "struct ID3DXSprite * g_pMenuButtonSprite" (?g_pMenuButtonSprite@@3PAUID3DXSprite@@A) already defined in MenuButton.obj does anyone know the cause of this? and hopefully a solution? my first thought was just that the .obj files hadn't been updated, so i tried to clean the solution, and continued getting this error, i even deleted the .obj files, and the compiler (visual studio 2005) simply created new ones (as i was hoping) and generated the same errors (not quite what i was expecting). Thanks in advance, Mal'
Evil Steve
Evil Steve
It's nothing to do with D3D - You can only set a value for a global once in an application, whereas you're trying to do it once per compilation unit.

The header should be:
extern LPDIRECT3DDEVICE9 g_pd3dDevice;extern LPDIRECT3DTEXTURE9 g_pMenuTexture;extern LPD3DXSPRITE g_pMenuButtonSprite;


And then in ONE source file, put:
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;LPDIRECT3DTEXTURE9 g_pMenuTexture = NULL;LPD3DXSPRITE g_pMenuButtonSprite = NULL;

And it should all work.
Stowelly
Stowelly
either u have the same objects declared elsewhere in your program, or you just need to click build-> clean solution then rebuild

also im assuming u have been using either #pragma once or #ifndef
http://stowelly.co.uk/
Malazar
Malazar
Evil Steve saves the day (once again), thanks, mate :D

thanks to stowelly for his reply as well :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.