Jump to content

  • Log In with Google      Sign In   
  • Create Account

Crusable

Member Since 27 Nov 2011
Offline Last Active Oct 17 2014 11:54 PM

Topics I've Started

typedef, structs, and arrays

30 January 2014 - 01:10 AM

Hello, I have a struct that defines an RGBA colour: 

struct Colour{
	float r; 
	float g;
	float b;
	float a;
};

Then I have an array of some predefined colours  so instead of having  to write out something link display.clear(Colour(1.f, 0.f, 0.f, 1.f) I would instead write  display.clear(clr::red); So I have an array of colours: 

//pre defined colours 
Colour colours[6] = {{1.f, 0.f, 0.f, 1.f},
					 {1.f, 0.f, 0.f, 1.f},
					 {1.f, 0.f, 0.f, 1.f},
					 {1.f, 0.f, 0.f, 1.f},
					 {1.f, 0.f, 0.f, 1.f},
					 {1.f, 0.f, 0.f, 1.f}};

Now here is my problem. I want to typedef all the elements in the array so instated of writing clr::colours[0] I write clr::red. SO I tried writing them like this and it did not work: 

namespace clr{
	typedef colours[0] red;
	typedef colours[1] green;
	typedef colours[2] blue;
	typedef colours[3] magenta;
	typedef colours[4] white;
	typedef colours[5] black;
}//namespace clr

Is this possible or did I just do it wrong?  Thanks for any help.


SFML Texture errors

31 December 2013 - 02:48 AM

Hello, I recently got a new pc with windows 8. I tried to compile a project on this new computer with the same IDE and the same version on SFML as  on my old windows 7 laptop, and I get this error repeated in my console window.

An internal OpenGL call failed in Texture.cpp (146) : GL_INVALID_ENUM, an unacce
ptable value has been specified for an enumerated argument
An internal OpenGL call failed in Texture.cpp (147) : GL_INVALID_ENUM, an unacce
ptable value has been specified for an enumerated argument

The only thing I can think of is the graphics card. All the projects compile fine on my old laptop, which has a better graphics card but worse cpu and less ram. Thanks for any help.


Sorting std::vectors

14 December 2013 - 09:50 PM

Hello, I am making a picture matching game(you have a picture and a jumbled picture and you need to make them match),  and so I have a vector of tiles(2d squares with colour). When I move the selected tile it changes the position of the tile it moved onto to its old position. However, this does not change its position in the vector so when trying to see if the picture matches the one I just made, it doesn't work. I need a way to, after I move the tile, update the vector so the order of the tiles in the map is 0 - n and it isn't all jumbled up. I tried std::sort but that doesn't seem to work. Thanks for any help.I included a pic to help demonstrate the movement.Attached File  Problem.png   659bytes   6 downloads


Compiling SDL2 with MinGW through Command line

10 December 2013 - 12:36 AM

Hello, I am tyring to comile a project with SDL2 through command line with MinGw. I have a run.bat file that looks like so:

 

g++ -o Game.exe Main/Main.cpp -lmingw32 -lSDL2main -mwindows -lSDL2 
pause
start /d "C:\Users\Mathew Bergen\Documents\Programming\C++\LD Practice" Game.exe

I get these errors:

c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/libmingw32.a(main.
o): In function `main':
e:\p\giaw\src\pkg\mingwrt-4.0.3-1-mingw32-src\bld/../mingwrt-4.0.3-1-mingw32-src
/src/libcrt/crt/main.c:91: undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

I googled the WInMain@16 error and I found that I needed to add -mwindows to the linking command, but it still does not work. I am on windows 7, Thanks for any help.


std::vector memory leak issues

12 November 2013 - 02:57 AM

Hello, I have an entity with a std::vector<Component*> m_components (Component is an abstract base class all other Components inherit from so I can polymorph them) and when I destroy the entity I clear the vector like so:

Entity::~Entity(){
	for(std::vector<Component*>::iterator iter = m_components.begin(); iter != m_components.end(); ++iter){
		delete *iter;
		*iter = NULL;
	}
	m_components.clear();
	m_components.shrink_to_fit();
} 

and I get memory leaks. I looked online and everywhere I look it looks like I am doing it right. The memory leaks are a jumble of numbers:

Detected memory leaks!
Dumping objects ->
{377} normal block at 0x05804D28, 8 bytes long.
 Data: < N      > 90 4E 80 05 00 00 00 00 
{376} normal block at 0x05804E80, 80 bytes long.
 Data: <  c   w   c     > 90 B1 63 05 D8 81 77 05 90 B1 63 05 00 00 CD CD 
{374} normal block at 0x05884028, 98304 bytes long.
 Data: <                > 00 00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 
{373} normal block at 0x05804E38, 8 bytes long.
 Data: < M      > A4 4D 80 05 00 00 00 00 
{372} normal block at 0x05804DF0, 8 bytes long.
 Data: < M      > 80 4D 80 05 00 00 00 00 
{371} normal block at 0x05804D70, 68 bytes long.
 Data: <  c   w   c     > C8 B0 63 05 C8 80 77 05 C8 B0 63 05 00 00 CD CD 
{353} normal block at 0x05778268, 8 bytes long.
 Data: <  w     > E8 81 77 05 00 00 00 00 
{352} normal block at 0x057781D8, 80 bytes long.
 Data: <  c  *x  N      > 90 B1 63 05 10 2A 78 05 80 4E 80 05 01 00 CD CD 
{350} normal block at 0x057839A0, 262144 bytes long.
 Data: < $   $   $   $  > 83 24 0C FF 83 24 0C FF 83 24 0C FF 83 24 0C FF 
{349} normal block at 0x05778190, 8 bytes long.
 Data: <  w     > FC 80 77 05 00 00 00 00 
{348} normal block at 0x05778148, 8 bytes long.
 Data: <  w     > D8 80 77 05 00 00 00 00 
{347} normal block at 0x057780C8, 68 bytes long.
 Data: <  c   x pM      > C8 B0 63 05 08 19 78 05 70 4D 80 05 01 00 CD CD 
{326} normal block at 0x05772908, 8 bytes long.
 Data: < *x     > 20 2A 78 05 00 00 00 00 
{325} normal block at 0x05782A10, 80 bytes long.
 Data: < &w   c   w     > 18 26 77 05 90 B1 63 05 D8 81 77 05 01 00 CD CD 
{323} normal block at 0x057819D0, 4096 bytes long.
 Data: <                > FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF 
{322} normal block at 0x05781988, 8 bytes long.
 Data: << x     > 3C 19 78 05 00 00 00 00 
{321} normal block at 0x05772950, 8 bytes long.
 Data: <  x     > 18 19 78 05 00 00 00 00 
{320} normal block at 0x05781908, 68 bytes long.
 Data: <@"w   c   w     > 40 22 77 05 C8 B0 63 05 C8 80 77 05 01 00 CD CD 
{303} normal block at 0x0577A100, 8 bytes long.
 Data: <(&w     > 28 26 77 05 00 00 00 00 
{302} normal block at 0x05772618, 80 bytes long.
 Data: <  c  *x   c     > 90 B1 63 05 10 2A 78 05 90 B1 63 05 01 00 CD CD 
{299} normal block at 0x05779030, 4096 bytes long.
 Data: <                > FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF 
{298} normal block at 0x05772308, 8 bytes long.
 Data: <t"w     > 74 22 77 05 00 00 00 00 
{297} normal block at 0x057722C0, 8 bytes long.
 Data: <P"w     > 50 22 77 05 00 00 00 00 
{296} normal block at 0x05772240, 68 bytes long.
 Data: <  c   x   c     > C8 B0 63 05 08 19 78 05 C8 B0 63 05 01 00 CD CD 
{275} normal block at 0x0563B220, 8 bytes long.
 Data: <| c     > 7C B0 63 05 00 00 00 00 
{274} normal block at 0x0563B190, 80 bytes long.
 Data: < &w  *x  N      > 18 26 77 05 10 2A 78 05 80 4E 80 05 01 01 CD CD 
{273} normal block at 0x0563B148, 8 bytes long.
 Data: <p c     > 70 B0 63 05 00 00 00 00 
{272} normal block at 0x0563B0C8, 68 bytes long.
 Data: <@"w   x pM      > 40 22 77 05 08 19 78 05 70 4D 80 05 01 01 CD CD 
{271} normal block at 0x0563B070, 24 bytes long.
 Data: <H c   c       c > 48 B1 63 05 C8 B0 63 05 04 00 00 00 20 B2 63 05 
{171} normal block at 0x0357F378, 40 bytes long.
 Data: <  5_            > D4 C5 35 5F 18 00 00 00 08 00 00 00 00 00 00 00 
{170} normal block at 0x003FBFE8, 40 bytes long.
 Data: <  5_            > D4 C5 35 5F 18 00 00 00 08 00 00 00 00 00 00 00 
Object dump complete.

I am using VS2012's built in system for detecting memory leaks. This is the only place I am dynamically allocating anything in my program and when I comment out everything that has to do with the vector I get no errors. Thanks for any help.


PARTNERS