Jump to content

finished (sound-) sources are released every frame


Ma-Shell
 Share

Recommended Posts

Hi,

 

When a source has finished playing it gets released every frame. This is a problem, if you want to find out, if it has finished playing, as you can't keep the source (even if you add n AddRefs() for the source, the source will be gone n frames after it finished playing).

 

You can see this by adding a global static variable:

 

[App.h add as class-member]
static Source* src;

[App.cpp]
Source* App::src;

[App.cpp: App::Start()]
Sound* s = Sound::Load("Sound\\Footsteps\\jump.wav");
Entity* e = world->entities.front();
e->EmitSound(s);
src = SoundDriver::GetCurrent()->sources.front();
src->AddRef();
src->AddRef();
src->AddRef();
src->AddRef();

[App.cpp: App::Loop()]
printf("Time: %f, Refs: %i\n", src->GetTime(), src->GetRefCount());

 

Will lead to the following output:

(...)
Time: 0.074989, Refs: 5
(...)
Time: 0.000000, Refs: 5
Time: 0.000000, Refs: 4
Time: 0.000000, Refs: 3
Time: 0.000000, Refs: 2
Time: 0.000000, Refs: 1

And an access violation after that, when accessing the GetTime()-method of the source.

 

The expected behaviour would be, that the RefCount is decreased only once, so if I added Refs before, I have to release it myself.

I even tried, setting "src->autorelease = false" but that didn't change anything.

  • Upvote 1
Link to comment
Share on other sites

  • 1 month later...

Well, the whole point of EmitSound is an easy way to make an entity make some noise. I didn't want it to require any additional management.

 

What about the response you posted here: http://www.leadwerks.com/werkspace/topic/10830-entityemitsound-loop-stop-and-restart/#entry79363

 

Is this forthcoming?

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Well, the whole point of EmitSound is an easy way to make an entity make some noise. I didn't want it to require any additional management.

 

But the only time you would have to do any additional management is, if you want to. If you don't want additional management, you just don't get yourself a reference and don't call addRef. wink.png

That's exactly the purpose of the reference-counter-concept.

 

If you want more control over your played sounds you can always use the source class.

That's exactly, what I'm doing here but only I let EmitSound create the source for me and then get myself a pointer to that instance.

Or does this problem not occur, if I create the source myself?

 

What about the response you posted here: http://www.leadwerks.com/werkspace/topic/10830-entityemitsound-loop-stop-and-restart/#entry79363

 

Is this forthcoming?

There is no point in getting a reference to the created source, if this is the intended design, as you can not be sure, the source is still there, when you want to access it.

Link to comment
Share on other sites

Well, the whole point of EmitSound is an easy way to make an entity make some noise. I didn't want it to require any additional management.

 

Finally found some time and noticed, this also happens, if I create the source myself, without the use of EmitSound but with "Create", "SetSound" and "Play". From your statement I read, EmitSound should just be a convenient way for doing that, which makes sure, I never use a reference to the created source.

 

The way it is currently there is absolutely no point in getting a reference to a source and use that, as you can never be sure, it does not vanish, before you use it. That fact is taking a lot of possibilities from you for actually no advantage. sad.png

I can only repeat: That is, what a reference counter is for... Everyone, who needs a reference increases the refcount and when it is done, it releases it, with the last one destroying the object. So, if I need a reference, I explicitly increase the refcount and when I'm done, I release it. Meanwhile the engine increases the refcount by ONE, while it plays the sound and decreases by ONE, when it is done.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...