• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

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

thuned

trouble using "delete"

8 posts in this topic

here's a piece of my code. uncommenting the delete would lead to crashing but i have no idea y
  
CTextureManager::CTextureManager()
{
	TextureList = new CBinaryArray<CTexture>(Compare);
}

CTextureManager::CTextureManager(GLuint size)
{
	TextureList = new CBinaryArray<CTexture>(Compare,size);
}

CTextureManager::~CTextureManager()
{
	/*
	if (TextureList)
		delete TextureList;
	/**/
}
   
i don't know if this matters but i declared by using this
  
CBinaryArray<CTexture>* TextureList;
   
life is unfair, take advantage of it. UNMB2 - if the link doesn't work, try clicking it Edited by - thuned on July 21, 2001 10:41:11 PM
0

Share this post


Link to post
Share on other sites
First thing, something simple to help keep your code clean. Rather than this:
  
if (TextureList)
delete TextureList;

you can safely do this:
  
delete TextureList;

since the language states that delete NULL is okay to do.

Now, as to your problem, I don't see anything wrong offhand. Perhaps something in the CBinaryArray class is causing a problem? Is it your class or a library? If yours or if you have the library source, I suggest using the debugger to step into the delete function and find out what specifically is causing the problem. Debuggers also usually have the ability to break on exception, to help find problems such as this.


---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!


Edited by - mossmoss on July 21, 2001 12:36:04 AM
0

Share this post


Link to post
Share on other sites
If it crashes when you call delete, then it''s usually a sign that you''ve written past the end of the allocated memory. The problem with memory accesses is that in most cases, it difficult to figure out if you''ve written one or two bytes past the end of the memory (unless they go over a page boundary) so the debug new will add an extra few bytes to the start and end of the memory block, and delete will check if you''ve changed any of those values. If you have, you''ll get a crash.

Debugging these problems is extremely difficult (unless you''re lucky enough to own BoundsChecker or some similar software).

I can''t really give you any solution, except check (throroughly!) for memory over/under runs.


War Worlds - A 3D Real-Time Strategy game in development.
0

Share this post


Link to post
Share on other sites
Make sure you are not changing the address of TextureList anywhere. An easy way to check this is to create another pointer and make newpointer = TextureList in your constructor after you call new TextureList. Then in your destructor check to see that newpointer still == TextureList before deleting. If they are not equivalent then either you are changing (possibly incrementing?) TextureList, or something is overwriting the memory that holds your TextureList pointer.

Seeya
Krippy
0

Share this post


Link to post
Share on other sites
quote:
Original post by Krippy2k
Make sure you are not changing the address of TextureList anywhere. An easy way to check this is to create another pointer and make newpointer = TextureList in your constructor after you call new TextureList. Then in your destructor check to see that newpointer still == TextureList before deleting. If they are not equivalent then either you are changing (possibly incrementing?) TextureList, or something is overwriting the memory that holds your TextureList pointer.

Seeya
Krippy


what happens if i do change it?
  
BOOL CTextureManager::SetAmount(GLuint amount)
{
return pTextureList->Resize(amount);
}

that creates a new vector, copies the old one over, and then deletes the old one, then set the pointer to the new one. could that be the problem?

0

Share this post


Link to post
Share on other sites
and how do i check for memory over/under runs?
and i don''t really know how to debug. well, for console based i have no problems, but win32 debug doesn''t seem to work for me
0

Share this post


Link to post
Share on other sites
The best way to test for memory over and under runs is to overload new and delete. I''m sure there''s other ways, but this is probably the easiest (and most flexible). In your new version of new, just allocate, say, 32 extra bytes and fill them with a certain character (not 0, but anything else should be fine) then return a pointer that''s 16 bytes into your allocated block. In the delete operator, check the 16 bytes before and 16 bytes after (you''ll have to store the length of the memory as well) and make sure they''re the same. If they''re not the original character you put there, then there''s been an overrun. There''s no way to (easily) test what caused the over run, unless you''ve got something like BoundsChecker, so to figure out what''s actually causing it will take several hours of just staring at the code

It''s probably tempting at this point to leave the delete commented out and maybe come back to the problem later, but I strongly suggest you figure out the bug now because it''s probably a symptom of a much bigger problem...


War Worlds - A 3D Real-Time Strategy game in development.
0

Share this post


Link to post
Share on other sites
What is the relationship of pTextureList to TextureList? Not sure exactly what''s going on there. lol

If you delete something, reallocate it and set the pointer to the newly allocated object, then there should not be a problem.

If your pointer is pointing to memory that was already deleted, it will crash. If your pointer is pointing to somewhere within an allocated block of memory other than the beginning of that allocated block it will crash. If it is pointing to the beginning of a previously allocated chunk of memory you should be ok.

Seeya
Krippy
0

Share this post


Link to post
Share on other sites
thanks all!
i fixed it.
somewhere else in my code i called delete but forgot to set it pointing to null
0

Share this post


Link to post
Share on other sites