• 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.
Sign in to follow this  
Followers 0
KoldGames

FMOD causing memory leaks?

17 posts in this topic

Hello!  I was using GlowCode to find memory leaks and saw that FMOD seems to be causing some:

przu.png

erwj.png

bbe6.png

Any help? Thanks! smile.png

Edited by KoldGames
0

Share this post


Link to post
Share on other sites

I can't see anything from the pictures, so this is 100% blind guesswork.

 

First, I'll guess you're talking about the sound library since obviously the FMOD instruction can't cause a leak and no other fmod jumps out at me. If that's the case, are you calling FMOD::Sound::release() after you finish using a sound? Being able to read the pictures might provide a better idea what functions you're calling and not calling for a better guess, but I just can't read the text in those pictures at all.

0

Share this post


Link to post
Share on other sites

Without really knowing anything about FMOD, it looks like the supposed leaks are in its initialization functions. Are you sure you are doing everything you need to do to properly unintialize FMOD prior to exiting your game?

0

Share this post


Link to post
Share on other sites

Are you calling System::release() when you're exiting your program? It looks like all of the leaks are from init(), so it's not memory constantly leaking or something. It's not even memory you'd ever have available for use during normal execution of your program (unless you release and create FMOD a lot, which you shouldn't).

 

If you are calling release(), make sure you're not nulling any relevant pointers or stomping on FMOD's memory or such before calling release() since you had your entire program's execution time to accidentally corrupt the data needed by FMOD to shutdown correctly.

0

Share this post


Link to post
Share on other sites

Are you sure you are doing everything you need to do to properly unintialize FMOD prior to exiting your game?

 

Yep, I believe so.  I call System::Release(), then set System to NULL, and delete the pointer.

 

 

 


If you are calling release(), make sure you're not nulling any relevant pointers or stomping on FMOD's memory or such before calling release() since you had your entire program's execution time to accidentally corrupt the data needed by FMOD to shutdown correctly.

 

I tried removing any FMOD related code from my application while only leaving the NXAudio's Initialize, Update, and Dispose functions, but still have a memory leak.  Very weird.

 

Here's my NXAudio class code:

FMOD::System* NXAudio::System = nullptr;
		FMOD_RESULT result;

		bool NXAudio::Initialize()
		{
			ZeroMemory(&System, sizeof(FMOD::System*));

			result = FMOD::System_Create(&System);
			if (result != FMOD_OK)
				return false;

			result = System->init(100, FMOD_INIT_NORMAL, 0);
			if (result != FMOD_OK)
				return false;

			return true;
		}

		FMOD_RESULT NXAudio::Update()
		{
			return System->update();
		}

		void NXAudio::Dispose()
		{
			if (System)
			{
				System->release();
				System = nullptr;
				delete System;
			}
			
			return;
		}

		FMOD_RESULT NXAudio::CreateSound(const char* name, FMOD_MODE mode, FMOD_CREATESOUNDEXINFO* exInfo, FMOD::Sound** sound)
		{
			return System->createSound(name, mode, exInfo, sound);
		}

		FMOD_RESULT NXAudio::CreateStream(const char* name, FMOD_MODE mode, FMOD_CREATESOUNDEXINFO* exInfo, FMOD::Sound** sound)
		{
			return System->createStream(name, mode, exInfo, sound);
		}

		FMOD_RESULT NXAudio::PlaySound(FMOD::Sound* sound, FMOD::ChannelGroup* channelGroup, bool paused, FMOD::Channel** channel)
		{
			return System->playSound(sound, channelGroup, paused, channel);
		}

The ZeroMemory line wasn't there before, I added that last night when I was trying to fix the leak.  The leak won't go away with or without.  I set FMOD up exactly like the documentation says (aside from having it in a static class).  Could the fact that System is static be the problem?

Edited by KoldGames
0

Share this post


Link to post
Share on other sites


 I set FMOD up exactly like the documentation says (aside from having it in a static class).  Could the fact that System is static be the problem?

 

While it may be bad practice, it shouldn't really make a difference, since System is just a raw pointer (and so you're not relying on any kind of automatic destruction). You've verified by stepping through the debugger that NXAudio::Dispose is called and System->release gets called?

0

Share this post


Link to post
Share on other sites


You've verified by stepping through the debugger that NXAudio::Dispose is called and System->release gets called?

 

Yep!  I put a breakpoint on it and it is being called.

0

Share this post


Link to post
Share on other sites

 

Here's my NXAudio class code:

		void NXAudio::Dispose()
		{
			if (System)
			{
				System->release();
				System = nullptr;
				delete System;
			}
			
			return;
		}

 

Delete should be before setting to nullptr.

0

Share this post


Link to post
Share on other sites


Delete should be before setting to nullptr.

 

When deleting before setting to nullptr, I get this error:

1jv3.png

0

Share this post


Link to post
Share on other sites

Then you have a memory overflow bug somewhere in your application that is corrupting memory around the System object, you are deleting it twice, or the pointer was not created via new.

Since it was created via FMOD::System_Create(), why are you deleting it?  Tutorials show to just call System->release().

 

 

L. Spiro

Edited by L. Spiro
1

Share this post


Link to post
Share on other sites


why are you deleting it?

 

I'm still learning C++ and thought I had to delete it because it was a pointer. lol

0

Share this post


Link to post
Share on other sites

I would recommend grabbing the return value from System::release(). You might get an error from that which would tell you what is wrong. In any case, an error on release() would probably result in leaks.

 

I might be wrong on this, so you'll have to do a little homework to make sure. I think you're supposed to have a close() call paired with the init(), and release() gets paired with the create(). You'll also really want to pay attention to the errors that get returned for every part you shut down. Later, you'll probably have quite a few components to shutdown and they have to be in the right order. You'll also have calls that can fail if the hardware is still in use from a prior sound call, and other stuff like that.

0

Share this post


Link to post
Share on other sites

Just a stab in the dark, but are you allocating something and putting it in 'System' before you pass 'System' to FMOD::System_Create()? If so, then don't (that would cause a memory leak).

A few miscellanea:

*Don't ZeroMemory() the pointer. That's just silly.

*As was indicated, if you set the pointer to null and then delete it, you should be getting a segfault. Don't do that. (There's no reason to do either of those things. FMOD will free the memory it allocated when you call System->release().)

*No offense, but why does this class exist? All it appears to do is act as more-or-less a direct pass-thru for the FMOD system interface.

 

Please read the documentation that came with FMOD about how to start up the system correctly. It's on page 8 of "Getting started with FMOD for Windows.pdf".

 

Please research the RAII design pattern. Mastering RAII is the 'correct' way to avoid memory leaks in C++, and it also helps with things like exception safety and even makes it easier and more natural-feeling to use your objects!

1

Share this post


Link to post
Share on other sites

Sorry it took so long to reply!  I've been busy. I have a question.  If the memory leaks only happen during initialization, is that a big problem? As long as my application is not creating leaks during runtime, am I correct?  I noticed that on my applications startup with GlowCode enabled, it finds the leaks when I search, but if I click Clear, and search for memory leaks then, I get 1 leak with VSync off (On my swapchain's Present method) and 0 with VSync on.  Thanks! smile.png

Edited by KoldGames
0

Share this post


Link to post
Share on other sites

If the memory leaks only happen during initialization, is that a big problem?

All leaks should be treated seriously. It is extremely bad practice to let the operating system clean up your messes on application shut-down and I would never hire someone who disagreed with that.
The people who do that will be the ruin of your project some day.


L. Spiro
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0