0

I have been working on playing midi files within pygame and keep getting faced with this error.

Fatal Python error: (pygame parachute) Segmentation Fault

Python runtime state: initialized

This is my code:

import pygame.midi
pygame.midi.init()
device = pygame.midi.get_default_output_id()
player = pygame.midi.Output(0)

the fault is highlighted to be an issue with the final line, but I'm not entirely sure what is wrong with it.

Thank you!

Community
  • 1
  • 1
CodingForFun
  • 11
  • 1
  • 3

3 Answers3

0

I think this is a bug in Pygame, but there was nothing in the tracker seeming to match. I can replicate the issue with PyGame 1.9.4.post1.

The cause of the issue is calling pygame.midi.Output(), I played around with a few different calls to this, specifying different parameters gives different errors - sometimes on call, but other times on shutdown.

It's a workaround, not a solution - but do you actually need to call this function? Basic MIDI functionality seems to work without it. The code below plays a MIDI file, then exits cleanly.

import sys
import pygame
import pygame.midi

pygame.init()
pygame.midi.init()
pygame.mixer.init()

midi_file = "popcorn.mid"
pygame.mixer.music.load( midi_file )
pygame.mixer.music.play()
device = pygame.midi.get_default_output_id()
device_info = pygame.midi.get_device_info( device )
print( "MIDI Device: " + str( device ) )
print( "Device Info: " + str( device_info ) )
#player = pygame.midi.Output( device, buffer_size=4096 )

clock = pygame.time.Clock()
while pygame.mixer.music.get_busy():
    pygame.time.delay( 1500 )
    print("", end='')
    sys.stdout.flush()   # just ensure the tick-mark is printed in-time

pygame.mixer.music.stop()
pygame.quit()

Maybe a later version of PyGame - perhaps even the (upcoming?) SDL2 version.

Kingsley
  • 14,398
  • 5
  • 31
  • 53
0

It should be an error related to C implementation. Please see if the following command works:

apt-get install -y xserver-xorg
caocao
  • 1
0

So I was facing the same issue It was due to cross platform issues like I was trying to use in on debian raspberri py so what I had to do was in the code top had to place this which ressolved this issue .

if os.uname()[4].startswith("arm") and os.environ.get("DISPLAY", "") == "":
    os.environ["SDL_VIDEODRIVER"] = "fbcon"
    os.environ["SDL_FBDEV"] = "/dev/fb1"
    os.environ["SDL_MOUSEDRV"] = "TSLIB"
    os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen"