0
0

[b:2tjaammj]Q1:[/b:2tjaammj] Does FMOD Studio cache EventDescription objects internally or is it loading from disk every time I call System::getEvent()?

[b:2tjaammj]Q2:[/b:2tjaammj] Does EventInstance support copy by value? For example, a sound plays with the following code:

[code:2tjaammj]FMOD::Studio::EventInstance eventInstance;
eventDescription.createInstance(&eventInstance);

FMOD::Studio::EventInstance copy = eventInstance;
copy.start();[/code:2tjaammj]

However, when I used this trick, FMOD would crash when I called System::release(). Should I avoid copying and instead rely on allocating heap memory for long term EventInstance objects?

  • You must to post comments
0
0

[quote:38bu5aaj][b:38bu5aaj]Q1:[/b:38bu5aaj] Does FMOD Studio cache EventDescription objects internally or is it loading from disk every time I call System::getEvent()?[/quote:38bu5aaj]
Currently it caches them internally when you load the bank, so getEvent() doesn’t read anything from disk.

[quote:38bu5aaj][b:38bu5aaj]Q2:[/b:38bu5aaj] Does EventInstance support copy by value? For example, a sound plays with the following code:

[code:38bu5aaj]FMOD::Studio::EventInstance eventInstance;
eventDescription.createInstance(&eventInstance);

FMOD::Studio::EventInstance copy = eventInstance;
copy.start();[/code:38bu5aaj][/quote:38bu5aaj]
You can copy EventInstance handles like that, but they will both refer to the same event instance internally. If you want more than one event instance, you need to call createInstance() multiple times.

[quote:38bu5aaj]However, when I used this trick, FMOD would crash when I called System::release(). Should I avoid copying and instead rely on allocating heap memory for long term EventInstance objects?[/quote:38bu5aaj]
This shouldn’t cause a crash – sorry about that! We’ll look into it.

  • You must to post comments
0
0

[quote="ben":3fk7b7kq][quote:3fk7b7kq]However, when I used this trick, FMOD would crash when I called System::release(). Should I avoid copying and instead rely on allocating heap memory for long term EventInstance objects?[/quote:3fk7b7kq]
This shouldn’t cause a crash – sorry about that! We’ll look into it.[/quote:3fk7b7kq]
I haven’t been able to reproduce this crash here. Could you email a code sample that causes the crash to support@fmod.org so we can look into it?

  • You must to post comments
0
0

Thanks for the clarifications! The code I had that took advantage of copying EventInstances was mixed in with other game systems so it’s possible that it was something else. When I have time I’ll try to create a simplified version that reproduces the problem.

  • You must to post comments
0
0

[quote="ben":18jsu3ak][quote="ben":18jsu3ak][quote:18jsu3ak]However, when I used this trick, FMOD would crash when I called System::release(). Should I avoid copying and instead rely on allocating heap memory for long term EventInstance objects?[/quote:18jsu3ak]
This shouldn’t cause a crash – sorry about that! We’ll look into it.[/quote:18jsu3ak]
I haven’t been able to reproduce this crash here. Could you email a code sample that causes the crash to support@fmod.org so we can look into it?[/quote:18jsu3ak]

I discovered that the crash occurs when calling EventDescription::createInstance on an uninitialized block of memory. I am using [url=http://www.lua.org/pil/28.1.html:18jsu3ak]Lua userdata[/url:18jsu3ak] to store my FMOD EventInstances, which doesn’t initialize the memory when it is allocated. I have to use placement new to explicitly construct the EventInstance, at which point I can use it safely.

Here is the relevant code, for anyone else who might run into this issue:
[code:18jsu3ak]FmodEventInstanceUserData* udata = static_cast<FmodEventInstanceUserData*>(lua_newuserdata(L, sizeof(FmodEventInstanceUserData)));
new (&udata->instance) FMOD::Studio::EventInstance();
ERRCHECK( eventDescription.createInstance(&udata->instance) );[/code:18jsu3ak]

  • You must to post comments
0
0

Good to hear you have solved your problem. Are you exposing the EventInstance API to lua script? If so, you should also try to ensure the script calls the release() function when finished with the sound.

Also, you will want to set up a finalizer in lua that explicitly calls the EventInstance destructor, as explained here:

http://www.lua.org/manual/5.1/manual.html#2.10.1

In fact it should call release() and then the destructor. That will catch cases where the script isn’t calling release() and just letting your userdata go free, although since it is tied to garbage collection it may not happen in a particularly timely fashion. That isn’t a big deal but it could mean a few extra memory allocations hang around for longer than they might otherwise.

Let us know if you have any further issues.

  • You must to post comments
0
0

[quote="geoff":s6q8jlb9]Good to hear you have solved your problem. Are you exposing the EventInstance API to lua script? If so, you should also try to ensure the script calls the release() function when finished with the sound.

Also, you will want to set up a finalizer in lua that explicitly calls the EventInstance destructor, as explained here:

http://www.lua.org/manual/5.1/manual.html#2.10.1

In fact it should call release() and then the destructor. That will catch cases where the script isn’t calling release() and just letting your userdata go free, although since it is tied to garbage collection it may not happen in a particularly timely fashion. That isn’t a big deal but it could mean a few extra memory allocations hang around for longer than they might otherwise.

Let us know if you have any further issues.[/quote:s6q8jlb9]

Hey geoff, thanks for the advice! I am calling release() in the __gc metamethod like you suggest.

However, unless I’m missing something, I don’t think I can call the EventInstance destructor myself. According to fmod_studio.hpp, the EventInstance inherits its destructor from Handle, which in turn has a protected destructor that I can’t access. I assume C++ generates a default destructor for EventInstance but I can’t seem to access that either.

  • You must to post comments
0
0

You should be able to access the EventInstance destructor as in the following:

[code:1vrn23pn]
udata->instance.~EventInstance();
[/code:1vrn23pn]

  • You must to post comments
0
0

[quote="geoff":22vsuyya]You should be able to access the EventInstance destructor as in the following:

[code:22vsuyya]
udata->instance.~EventInstance();
[/code:22vsuyya][/quote:22vsuyya]

Ah, my problem was that I’m not using the FMOD namespace. Apparently it’s not possible to explicitly call destructors of objects unless you import the namespace.

This DOESNT work:

[code:22vsuyya]
instance.~FMOD::Studio::EventInstance();
[/code:22vsuyya]

Here is what I needed to do to get it to work:

[code:22vsuyya]{
using namespace FMOD::Studio;
instance.~EventInstance();
}[/code:22vsuyya]

Thanks for the help!

  • You must to post comments
Showing 8 results
Your Answer

Please first to submit.