Sound cutting out after 256 plays on windows cpp target

Using HaxeFlixel, typing out text letter by letter with FlxTypeText, playing each character, the typing sound effect cuts out exactly after the 255th character, with the music and any other sound effect cutting out as well shortly after.

Debugging through cmd, it throws these two errors:

The sound comes back on various actions like un/refocusing the game window or randomly on it’s own.

Weirdly,this error won’t happen when setting Windows 7’s color scheme to basic, disabling aero.

My best guess is the sound using a new channel each time it’s played, where it should just be re-using a single channel, as it’s only a single sound effect restarting over and ever without ever overlapping itself. I don’t understand enough about the magic behind HaxeFlixel and it’s components to validate that assumption, though.

If you want to try it for yourself, you can do so using the FlxTypeText demo from the flixel-demos repository, or really just playing any sound for more than 255 times in any project.

If you’d want to, you could take a look at the haxeflixel forums thread or the haxeflixel github issue I had on the problem. Especially the latter has a recent post pointing out some possibly helpful details.

azrafe7 investigated the problem over at the github issue, giving some good pointers on where to look into solving the problem within the OpenFL code base:

Investigating more it seems that the problem is related to the GC not kicking in fast enough.

If you try the updated gist and press space when the sound goes off, the GC will be forced to release the channels, and sound should work again.

@pizzamakesgames: you can also try it in your own case by adding:

#if cpp
    cpp.vm.Gc.run(false);
#end

Obviously this would only be a workaround (force-fire the GC based on some heuristic), so there’s still the need for a proper fix.

Bumping since this issue is sadly still present: https://github.com/openfl/openfl/issues/962