Coding Problem-ness

Forum Archive - from http://theuniversal.net
Locked
User avatar
Mattizme
Posts: 615
Joined: Sat Oct 04, 2003 6:23 pm
Location: At work/school/home
Contact:

Coding Problem-ness

Post by Mattizme »

http://www.mattkemp.co.uk/Stuff/Arcade.zip

Mit/New resident C monkey:

Arcade code above doesn't seem to like me. Whenever I try and run it (and select the new game) it gives no error for crash and just dumps to desktop with an obscure memory error. Personally, I'm not a master on assembly so I have no idea what the hell the disassembly of it means - any ideas?
User avatar
Magicfinger
Staff
Staff
Posts: 1078
Joined: Tue Sep 30, 2003 10:38 am
Location: here,there and everywhere

Post by Magicfinger »

its the two ZeroMemory(...) lines you got in the TLInitGraphics Procedure, im not too sure what you achieving with them there anyway but as far as i can see it has no operational implications when i comment them out :)


ok... comes back for an edit on this one... :)

spot the difference :)

int Blocks[8][150];

ZeroMemory( Blocks, sizeof( Blocks[0]) * 1200 );


anyway putting ....

ZeroMemory( Blocks, sizeof( Blocks[0][0] ) * 1200 );

stops the crash to desktop... but its memory like i got any idea what im talking about :)
User avatar
Mattizme
Posts: 615
Joined: Sat Oct 04, 2003 6:23 pm
Location: At work/school/home
Contact:

Post by Mattizme »

thanks, I though it may be something to do with the ZeroMemory-thingies, I think Mit put them in the original invaders and I've been copying them since not understanding properly what they did.; Tho thinking about it, there I have probably been zeroing 1200 times 150 integers, which I'm guessing isn't a small number :]
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

jus a note :
but as far as i can see it has no operational implications when i comment them out
not zeroing regions of memory often does seem to have no effect in debug (because most compilers clear all memory by default in debug mode), but then you'll find when you compile in release mode suddenly the memory you thought was empty is now full of random shite. (if you're lucky.. if youre unlucky the memory occupied in release mode will just happen to be full of 0s too, and then there'll seem to be no problems until your code is run some other time, or on someone elses machine, when the memory used happens not to be full of 0s)
Often the cause of weird intermittent bugs that seem to disappear when u try to debug em, so its always good practice to explicitly clear your memory before using it.
User avatar
Mattizme
Posts: 615
Joined: Sat Oct 04, 2003 6:23 pm
Location: At work/school/home
Contact:

Post by Mattizme »

I did wonder why u put em in there ;)
User avatar
Magicfinger
Staff
Staff
Posts: 1078
Joined: Tue Sep 30, 2003 10:38 am
Location: here,there and everywhere

Post by Magicfinger »

heh as i said memory... like i know what im talking about :)

<<goes off to read up on memory allocation/deallocation:)
User avatar
Mattizme
Posts: 615
Joined: Sat Oct 04, 2003 6:23 pm
Location: At work/school/home
Contact:

Post by Mattizme »

*me goes to read a book on how to actually program C (pickin' it up as I go along :])
Locked