Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Events for multiple windows  (Read 4383 times)

0 Members and 1 Guest are viewing this topic.

demolishun

  • Newbie
  • *
  • Posts: 2
    • View Profile
Events for multiple windows
« on: April 04, 2010, 07:56:22 am »
Version of SFML is 1.4
Platform is Ubuntu 9.04
Binding is Python

The problem is if I create two windows and call the GetEvent function for each the program corrupts something internally.  

The error is this:
*** glibc detected *** python: corrupted double-linked list: 0x09eb17f0 ***

This occurs after I have resized each window independently to test the resizing of the views.

Here is the code:
Code: [Select]

# Include the PySFML extension
from PySFML import sf

# background color
bgroundclr = sf.Color(127, 64, 64)

# Create the main window
window = sf.RenderWindow(sf.VideoMode(800, 600), "Kid's Game")
stats = sf.RenderWindow(sf.VideoMode(400, 400), "Kid's Game Stats")

# Create a graphical string to display
text = sf.String("Hi Kids!")
#windowsize = sf.String("%d %d" %(window.GetWidth(),window.GetHeight()))

# Start the game loop
running = True
while running:
    event = sf.Event()
    while window.GetEvent(event):
        if event.Type == sf.Event.Closed:
            running = False
        if event.Type == sf.Event.Resized:
            wview = window.GetView()
            wview.SetCenter(event.Size.Width/2, event.Size.Height/2)
            wview.SetHalfSize(event.Size.Width/2, event.Size.Height/2)
            window.SetView(wview)

    while stats.GetEvent(event):
        if event.Type == sf.Event.Resized:
            wview = stats.GetView()
            wview.SetCenter(event.Size.Width/2, event.Size.Height/2)
            wview.SetHalfSize(event.Size.Width/2, event.Size.Height/2)
            stats.SetView(wview)

    # Clear screen, draw the text, and update the window
    window.Clear(bgroundclr)
    stats.Clear(bgroundclr)

    tcenter = text.GetCenter()
    xpos = window.GetWidth()/2 - text.GetRect().GetWidth()/2
    ypos = window.GetHeight()/2 - text.GetRect().GetHeight()/2
    text.SetPosition(xpos, ypos)
    window.Draw(text)

    windowsize = sf.String("%d %d" % (window.GetWidth(),window.GetHeight()))
    #postxt = sf.String("%d %d" % (text.GetRect().GetWidth(),text.GetRect().GetHeight()))
    scale = text.GetSize()
    postxt = sf.String("%d %d %d" % (xpos,ypos,scale))
    postxt.SetPosition(0,100)


    stats.Draw(windowsize)
    stats.Draw(postxt)


    window.Display()
    stats.Display()

demolishun

  • Newbie
  • *
  • Posts: 2
    • View Profile
Events for multiple windows
« Reply #1 on: April 04, 2010, 08:18:18 am »
Okay, this is not an event issue.  It was because I was using the same variable for the View.  If I use a separate variable for the View it works great.  No crash, no collisions, no problem!

Here is the change:
Code: [Select]

while stats.GetEvent(event):
        if event.Type == sf.Event.Resized:
            wview2 = stats.GetView()
            wview2.SetCenter(event.Size.Width/2, event.Size.Height/2)
            wview2.SetHalfSize(event.Size.Width/2, event.Size.Height/2)
            stats.SetView(wview2)


 

anything