Wine randomly cannot initialize sound [ Wine and Pulseaudio fight for address space; workaround found ]

Bug #502375 reported by phanyx
66
This bug affects 12 people
Affects Status Importance Assigned to Milestone
alsa-plugins
Invalid
Undecided
Unassigned
wine (Fedora)
Won't Fix
Medium
wine1.2 (Ubuntu)
Invalid
Undecided
Unassigned
Nominated for Dapper by João Ricardo Lourenço
Nominated for Hardy by João Ricardo Lourenço
Nominated for Jaunty by João Ricardo Lourenço
Nominated for Karmic by João Ricardo Lourenço
Nominated for Lucid by João Ricardo Lourenço
Nominated for Maverick by João Ricardo Lourenço
wine1.3 (Ubuntu)
Fix Released
Undecided
Unassigned
Nominated for Dapper by João Ricardo Lourenço
Nominated for Hardy by João Ricardo Lourenço
Nominated for Jaunty by João Ricardo Lourenço
Nominated for Karmic by João Ricardo Lourenço
Nominated for Lucid by João Ricardo Lourenço
Nominated for Maverick by João Ricardo Lourenço

Bug Description

Binary package hint: wine1.2

I have a problem with wine - it randomly doesn't initialize sound.

The following cases were tested by running winecfg multiple times, one after another:

1. With wine1.2 set to use ALSA and when there is no more applications, that are producing sound, wine randomly gives multiple errors, that say: “mmap() failed: Cannot allocate memory”, but eventually starts and works properly.

2. With wine1.2 set to use ALSA and when there are applications, that are producing sound (e. g. Audacious2, Firefox while playing flash movies), wine randomly gives multiple errors, that say: “mmap() failed: Cannot allocate memory”, and one error, that says: “ALSA lib pcm_dmix.c:1008:(snd_pcm_dmix_open) unable to open slave”. After that wine runs the requested application, but without sound.

3. With wine1.2 from Neil Wilson's PPA with unofficial pulseaudio support and set to use Pulseaudio, wine randomly gives multiple errors, that say: “mmap() failed: Cannot allocate memory”, and one error, that say:
“xe: pulse.c:716: PULSE_WaveInit: Assertion `PULSE_context' failed.
err:module:attach_process_dlls "winmm.dll" failed to initialize, aborting
err:module:LdrInitializeThunk Main exe initialization for L"C:\\windows\\system32\\winecfg.exe" failed, status 80000101”.
After that, wine doesn't even start the requested application. That case occurs even, when there are no applications, that are producing sound at the moment.

The strange thing is, that the issue occurs randomly: sometimes wine will start just fine, but sometimes it will not. The issue is very frequent though.

ProblemType: Bug
Architecture: i386
Card0.Amixer.info:
 Card hw:0 'CA0106'/'Audigy SE [SB0570] at 0xd400 irq 17'
   Mixer name : 'CA0106'
   Components : ''
   Controls : 35
   Simple ctrls : 18
Date: Sat Jan 2 17:44:26 2010
DistroRelease: Ubuntu 9.10
InstallationMedia: Ubuntu 9.10 "Karmic Koala" - Release i386 (20091028.5)
NonfreeKernelModules: nvidia
Package: pulseaudio 1:0.9.19-0ubuntu4
ProcEnviron:
 LANG=pl_PL.UTF-8
 SHELL=/bin/bash
ProcVersionSignature: Ubuntu 2.6.31-17.54-generic
SourcePackage: pulseaudio
Uname: Linux 2.6.31-17-generic i686
mtime.conffile..etc.pulse.daemon.conf: 2009-12-07T01:27:14.270441

Revision history for this message
phanyx (phanyx-deactivatedaccount) wrote :
description: updated
description: updated
Revision history for this message
Scott Ritchie (scottritchie) wrote :

Similarly, sometimes sound will be very scratchy and "pop" in and out repeatedly.

One workaround I've discovered is to close other audio sources (especially Firefox+flash), killall -9 pulseaudio, wait about 10 seconds for it to restart automatically, and then run wine again. This seems to prevent the scratchy issues as well, although when another application (eg pidgin) generates audio they can often return.

Changed in wine1.2 (Ubuntu):
status: New → Confirmed
Revision history for this message
iltony (iltony) wrote :

You can fix winmm.dll problem, without recompiling the kernel, by setting your audio output to oss in winecfg. Run winecfg, switch to audio tab, select oss output. If you can't access winecfg, please try the following steps: disable any soundcard which is giving problem (i.e. remove usb soundcards, disable internal ones from bios), then run winecfg, set the right output, enable all your soundcards, reboot. For me, everything has worked fine since I took these steps. I'm running ubuntu karmik with kernel 2.6.31-9-rt #152-Ubuntu x86_64, internal soundcard: intel hda, external soundcard: hercules mk2 (usb).

Revision history for this message
dino99 (9d9) wrote :

can't use metatrader with wine due to this alsa problem:

alsa plug-in [wine preloader] freeze wine and hide mouse on active windows: huge cpu activity on pulseaudio and gnome-setting-daemon.

Googling around, some users says to deselect alsa and choose esound instead, what i have done in winecfg, then kill pulseaudio.
Wine work better but is very slow with this sound choice. Choising esound or oss does not help much.

Removing/purging alsa/pulseaudio then reinstall them does not work, erasing .pulse neither, nothing special in logs.

This is test on Lucid with wine 1.1.36 that was well working 2 weeks ago before last alsa upgrades.

Revision history for this message
iltony (iltony) wrote :

have you tried the command
pasuspender -- winecfg
?
You can start a program by issuing
pasuspender -- wine .wine/drive_c/Programmi/Macromedia/Flash\ 8/Flash.exe
It suspends pulseaudio for a while and lets you use wine without the hassles it brings.

Revision history for this message
dino99 (9d9) wrote :

this problem is not related to flash on my end

Revision history for this message
João Ricardo Lourenço (jorl17) wrote :

This is a serious problem which has been laying around for too long. If you, like myself, lurk around the WineHQ forums and AppDB, you will see MANY logs with the "mmap() failed: Cannot allocate memory" message. It seems, though, that these users do not care about it, probably because Wine ends up defaulting to direct hardware access, giving them sound if their soundcard is free.

I, however, have serious issues with this one, and have ran several tests to try and understand where the HELL this happens.

From my testing, the line "mmap() failed: Cannot allocate memory" dictates the problem. This happens with the ALSA plugin as well as with the Pulse plugin and does not seem to revert unless the app (wine) is restarted. In my tests, I forced Wine's drivers to retry running the code that fails to see if "mmap() failed" would go away. It never does.

With the ALSA driver, I was able to trace the error to this line of code code:

"rc = snd_pcm_open(&pcm, pcmname, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)"

inside the ALSA_AddUserSpecifiedDevice(). This happens when I specify the PCM device for Wine to use in the registry.

Now what I CAN'T figure out is what exactly outputs the mmap() function. Is it a library? Is it pulse? Something in the kernel? A module? I don't FREAKING KNOW, and that's driving me nuts.

I've checked out the code for both ALSA and Pulse to no avail, I cannot see if the code is in either. Who was the moron that coded that message and forgot to add other useful tracing? Who was it that made my recent days turn into bloody hell?

I suggest people help debugging this issue since I can't clearly do it myself. I can also tell you that this doesn't seem to have anything to do with Flash or with the crackling sound. The latter is another issue which can be (partially) solved by adding default-fragment-size-msec = 25 to Pulse's daemon.conf (in my case).

I would be grateful if anybody -- anyone -- would try and help to fix this issue, because it is making Ubuntu users struggle with Wine. This will not help Ubuntu in the long run, as it is CLEARLY an issue that was not present in 8.10 (which was my last decent working Ubuntu Release...). What we need to find is what application or library is emitting the god-damned mmap() message.

Thanks, my apologies for being this angry,

Jorl17

Revision history for this message
dino99 (9d9) wrote :

hi Joao,

have the same issue, might sid had, because my problems was not only with wine. If i was not having sound problem with Jaunty or Karmic, with Lucid it was a nightmare: pulseaudio might be started into console. In fact my hardware sound chipset: ALC882 (aka azalia / hda-intel / realtek) was not well recognized, so system/pref/sound cant be opened.
I finally made this working by removing/purging all alsa* & pulse* packages and related hidden files, then reinstalling. So it is on Lucid side, as often a transitional left behind settings/conf/packages that built the mess.

Now with wine, its quite the same thing: upgrading is at your own risk as said on winehq home, a clean install is far better. The problem is that you need to reinstall everything running with wine again.

note: to this sound problem, maybe the problem/solution stay into regedit config.

Revision history for this message
João Ricardo Lourenço (jorl17) wrote :

As additional info, I've been tracing the issue to see if it is somehow related to something that Wine does. I've managed to keep returning hackish values from the alsa driver loading code, all the way down (or up the stack) to LdrInitializeThunk. Yes, I actually was nuts enough to keep returning and handling hacked values continuously until I got to LdrInitializeThunk.

I've tried running loops in all of these steps (and I mean ALL, around 14 or so functions) but to no avail, they continuously trigger the error.

So, it seems that this must be something related to the way Wine is being loaded? Maybe there are different conditions making its interaction with the sound system vary? I don't know, my brain is damaged because of all that pseudo-debugging.

If I can do anything to help, just say it.

summary: - Wine randomly cannot initialize sound
+ Wine randomly cannot initialize sound [mmap() failed: ]
Revision history for this message
João Ricardo Lourenço (jorl17) wrote : Re: Wine randomly cannot initialize sound [mmap() failed: ]
Download full text (6.4 KiB)

I have confirmed that this is a bug in Pulseaudio. If it is disabled, Wine runs without a problem.

Alternatively, I have made a hack that works 100% on my PC and that I will share with you, hoping you will correct bad stuff I might have made here.

=== Hack ===

The trick I'll be using is redirecting Pulseaudio to use dmix and the like. This has its disadvantages: worse latency, double-mixing, but I haven't noticed them. However, I won't just let all the other apps use ALSA directly: I am going to edit alsa-lib's sources to trigger a change so that every device other than wine-default gets redirected to pulse.

There was *probably* a better way to do this, but I couldn't find it.

DO NOT FORGET TO BACKUP ANY FILES THAT I TELL YOU TO EDIT.

====== Step 1:

 Open up your ~/.asoundrc file. Delete everything in it (I mean everything) and paste the following in there:

== PASTE THE FOLLOWING: ==
# ALSA library configuration file

# Include settings that are under the control of asoundconf(1).
# (To disable these settings, comment out this line.)
#</home/jorl17/.asoundrc.asoundconf>
# ALSA library configuration file managed by asoundconf(1).

# Old Conf
defaults.pcm.nonblock 0
defaults.namehint.showall on
defaults.namehint.basic on
defaults.namehint.extended on
pcm.pulse {
type pulse
}

ctl.pulse {
type pulse
}

#pcm.!default {
# type pulse
#}

pcm.!dmixer {
        type dmix # plugin type
        ipc_key 5678293 # unique ipc id
        ipc_perm 0666 # would like to use icp_group instead
        ipc_key_add_uid no # share the same mixer with all users
        slave {
                pcm "hw:0,0"
                period_time 0 # needed by oss (= 0)
                period_size 1024 # needed by oss (= 2^n)
                period_size 8192 # needed by oss (= 2^n)
                format S32_LE
                rate 48000
        }
}
pcm.!dsnoop:0 {
        type pulse
}

== END PASTE THE FOLLOWING ==

This makes ALSA set its default device to dmix:0 and dsnoop:0, I believe. Since dsnoop:0 is used for input, we set it to pulse (Wine doesn't seem to have a problem with that).

====== Step 2:

Then, we will make Pulseaudio load up without blocking ALSA.

Edit /etc/pulse/default.pa (or make a user-specific config). Look for the line that reads "load-module module-udev-detect" (around line 54 and comment it out, by putting a '#' before). Then, scroll down to the end of the file and paste the following:

load-module module-alsa-source device=dsnoop:0
load-module module-alsa-sink device=dmix:0

That now makes Pulseaudio go through dmix and dsnoop. Maybe the dsnoop:0 part could be changed to something better, but I can't think of it right now.

====== Step 3:

We should now have Pulseaudio going through ALSA, but other devices will not go through Pulseaudio, since alsa's '!default' PCM isn't set to do that (which is something that we do not want). So, how do we get everything EXCEPT for Wine to go through the 'pulse' PCM that we created before?

My trick was to edit alsa-lib right at the source:

   sudo apt-get build-dep alsa-lib
   apt-get source alsa-l...

Read more...

summary: - Wine randomly cannot initialize sound [mmap() failed: ]
+ Wine randomly cannot initialize sound [Pulseaudio-related ; mmap()
+ failed: ]
Revision history for this message
João Ricardo Lourenço (jorl17) wrote : Re: Wine randomly cannot initialize sound [Pulseaudio-related ; mmap() failed: ]

Here's more news about the issue: https://bugzilla.redhat.com/show_bug.cgi?id=550736

So, as you see, it is a matter of interference between Pulse and Wine. It is fixable by, as suggested by a comment replacing
{ (void *)0x00110000, 0x6fef0000 }, /* low memory area */
with
{ (void *)0x00110000, 0x3fef0000 }, /* low memory area */
in loader/preloader.c in Wine's source.

The consequences in terms of Wine usability? I am not sure if there are any. Maybe we should ask Alexandre why he commited that patch?

summary: - Wine randomly cannot initialize sound [Pulseaudio-related ; mmap()
- failed: ]
+ Wine randomly cannot initialize sound [ Wine and Pulseaudio fight for
+ address space; workaround found ]
Revision history for this message
Raymond (superquad-vortex2) wrote :

>> Now what I CAN'T figure out is what exactly outputs the mmap() function. Is it a library? Is it pulse? Something in the kernel? A module? I don't FREAKING KNOW, and that's driving me nuts.

The reason is alsa-pulse plugin does not support snd_pcm_mmap_* functions

http://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m___direct.html

Revision history for this message
rusivi2 (rusivi2-deactivatedaccount) wrote :

Thank you for posting this bug.

Does this occur in newest WINE?

Changed in wine1.2 (Ubuntu):
status: Confirmed → Incomplete
Changed in alsa-plugins:
status: New → Incomplete
Revision history for this message
João Ricardo Lourenço (jorl17) wrote :

Sorry, but I can not test it right now, nor do I think I'll be able to in the future. Someone else will have to check it out.

Revision history for this message
dino99 (9d9) wrote :

Related to post #13 above:
- the answer is yes : still an issue with 1.3.34. I meanly use wine on ubuntu i386 (oneiric/precise) to run Metaquotes software:
 1) MT4 loads and immediatly crash (nothing logged) if using the default audio winecfg: all set to use "system default".
 2) but i dont get this issue if i change the audio winecfg settings to: default/default/HDA-intel-ALC882-analog/HDA-intel-ALC882-analog. So this seems to be an alsa/pulseaudio issue.
 3) MT5 was running without trouble till wine 1.3.30, but as MT5 is still a work in progress, the recent versions all freeze after 10 seconds and seems again an audio issue, but cant find a way via winecfg.

Changed in wine1.2 (Ubuntu):
status: Incomplete → Confirmed
status: Confirmed → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in wine1.3 (Ubuntu):
status: New → Confirmed
Revision history for this message
dino99 (9d9) wrote :

That issue is fixed with wine 1.5

Changed in wine1.3 (Ubuntu):
status: Confirmed → Fix Released
Changed in wine1.2 (Ubuntu):
status: Incomplete → Invalid
dino99 (9d9)
Changed in alsa-plugins:
status: Incomplete → Invalid
Changed in wine (Fedora):
importance: Unknown → Medium
status: Unknown → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.