0
0

I’ve modified the programmer sound example to set the subsoundsentence in the FSB during the FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_CREATE callback.

However I get this crash when calling event->start() as a result.

[quote:1vydwwe8]Unhandled exception at 0x0033ecd9 in programmer_sound.exe: 0xC0000005: Access violation reading location 0x00000000.[/quote:1vydwwe8]

Source Code for this example is as follows
[code:1vydwwe8]/*===============================================================================================
programmer_sound Example
Copyright (c), Firelight Technologies Pty, Ltd 2006-2007.

Demonstrates how to use the "programmer sound" feature of the FMOD event system
===============================================================================================*/

include "../../api/inc/fmod_event.hpp"

include <windows.h>

include <stdio.h>

include <stdlib.h>

include <conio.h>

const char *MEDIA_PATH = "..\media";
const char *FSB_NAME = "..\media\other.fsb";

FMOD::Sound *fsb;
FMOD::System *sys;

int soundlist[2] = { 0, 1 };

void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d)\n", result);
exit(-1);
}
}

FMOD_RESULT F_CALLBACK eventcallback(FMOD_EVENT *event, FMOD_EVENT_CALLBACKTYPE type, void *param1, void *param2, void *userdata)
{
FMOD_RESULT result;

switch (type)
{
    case FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_CREATE :
    {
        char *name      = (char *)param1;               // [in]  (char *) name of sound definition
        int entryindex  = *((int *)param2);             // [in]  (int) index of sound definition entry
        FMOD::Sound **s = (FMOD::Sound **)param2;       // [out] (FMOD::Sound *) a valid lower level API FMOD Sound handle


       // result = fsb-&gt;getSubSound(rand() % 4, s);
        result = fsb-&gt;setSubSoundSentence(soundlist,2 );
        *s = fsb;
       // result = FMOD_OK;
        ERRCHECK(result);

        printf(&quot;FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_CREATE %p\n&quot;, *s);
        break;
    }

    case FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_RELEASE :
    {
        FMOD::Sound *s = (FMOD::Sound *)param2;         // [in]  (FMOD::Sound *) the FMOD sound handle that was previously created in FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_CREATE
        printf(&quot;FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_RELEASE %p\n&quot;, s);
        break;
    }
}

return FMOD_OK;

}

int main(int argc, char *argv[])
{
FMOD_RESULT result;
FMOD::EventSystem *eventsystem;
FMOD::EventGroup *eventgroup;
FMOD::Event *event;
int key;

printf(&quot;======================================================================\n&quot;);
printf(&quot;Programmer Sound. Copyright (c) Firelight Technologies 2006-2007.\n&quot;);
printf(&quot;======================================================================\n&quot;);

result = FMOD::EventSystem_Create(&amp;eventsystem);
ERRCHECK(result);
result = eventsystem-&gt;init(64, FMOD_INIT_NORMAL, 0, FMOD_EVENT_INIT_NORMAL);
ERRCHECK(result);
result = eventsystem-&gt;setMediaPath((char *)MEDIA_PATH);
ERRCHECK(result);
result = eventsystem-&gt;load(&quot;examples.fev&quot;, 0, 0);
ERRCHECK(result);
result = eventsystem-&gt;getGroup(&quot;examples/examples&quot;, FMOD_EVENT_DEFAULT, &amp;eventgroup);
ERRCHECK(result);

result = eventsystem-&gt;getSystemObject(&amp;sys);
ERRCHECK(result);
result = sys-&gt;createStream(FSB_NAME, FMOD_2D | FMOD_SOFTWARE, 0, &amp;fsb);
ERRCHECK(result);

printf(&quot;======================================================================\n&quot;);
printf(&quot;Press SPACE  to start event\n&quot;);
printf(&quot;Press ESC    to quit\n&quot;);
printf(&quot;======================================================================\n&quot;);

key = 0;
do
{
    if (_kbhit())
    {
        key = _getch();

        if (key == ' ')
        {
            result = eventgroup-&gt;getEvent(&quot;programmersound&quot;, FMOD_EVENT_DEFAULT, &amp;event);
            if (result == FMOD_OK)
            {
                result = event-&gt;setCallback(eventcallback, 0);
                ERRCHECK(result);
                result = event-&gt;start();
                ERRCHECK(result);
            }
        }
    }

    result = eventsystem-&gt;update();
    ERRCHECK(result);

    Sleep(10);

} while (key != 27);

result = eventsystem-&gt;unload();
ERRCHECK(result);
result = fsb-&gt;release();
ERRCHECK(result);
result = eventsystem-&gt;release();
ERRCHECK(result);

return 0;

}
[/code:1vydwwe8]

Can anyone give me any ideas as to what I’ve done wrong?
I swear I’ve had similar code working in the past, although in that case I was sending the data for the sentance structure in the *userdata parameter of the callback. Although it seems that method no longer works either…

This seems to be a recent problem in later versions of both the Win32 and Xbox360 API’s, and probably means I’m doing something illegal. I’m just stumped as to what…

Any help, would be greatly appreciated.
Thank you.

  • You must to post comments
0
0

Thanks for that repro. It looks like the programmer sound wasnt expecting to have a ‘parent sound’ played (only subsounds), and it run into a null pointer.

I’ve just fixed this for our next release which should be soon.

  • You must to post comments
0
0

Thats fantastic news!

Thank you.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.