Ma-Shell Posted September 21, 2014 Share Posted September 21, 2014 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. 1 Quote Link to comment Share on other sites More sharing options...
whiterabbit Posted September 23, 2014 Share Posted September 23, 2014 I've experienced this as well, with Lua. I didn't go so far as to check why it was being released when I had manually AddRef()'d it, but this describes it perfectly. Quote Link to comment Share on other sites More sharing options...
Ma-Shell Posted October 29, 2014 Author Share Posted October 29, 2014 Josh, could you please confirm, whether this is the intended behavior or not. At the moment this is game breaking for me but I wouldn't want to do a (more or less dirty) workaround, if this is fixed anytime soon. Quote Link to comment Share on other sites More sharing options...
Josh Posted October 29, 2014 Share Posted October 29, 2014 This is intended behavior. The Entity::EmitSound() function creates an automatically managed source that deletes itself once it stops playing. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Ma-Shell Posted October 29, 2014 Author Share Posted October 29, 2014 Even if I called addRef? So it is basically impossible to find out, whether a source has finished playing. Quote Link to comment Share on other sites More sharing options...
Josh Posted October 29, 2014 Share Posted October 29, 2014 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. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
beo6 Posted October 29, 2014 Share Posted October 29, 2014 If you want more control over your played sounds you can always use the source class. Quote Link to comment Share on other sites More sharing options...
macklebee Posted October 29, 2014 Share Posted October 29, 2014 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? Quote 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 More sharing options...
Ma-Shell Posted October 30, 2014 Author Share Posted October 30, 2014 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. 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. Quote Link to comment Share on other sites More sharing options...
Ma-Shell Posted November 4, 2014 Author Share Posted November 4, 2014 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. 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. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.