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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - olie258

Pages: [1]
1
Java / Obligatory 'loading resources on a thread' post.
« on: January 29, 2013, 10:49:26 pm »
Hello there,

I'm attempting to use a worker thread load textures and subsequently use these textures on the main thread but I'm running into a problem, specifically that these textures do not appear to be rendering.

I've included a minimal example that reproduces the problem below. I wonder if anyone can provide some insight into what may be going wrong here?

I'm using the January 29th JSFML test release on Windows (64 bit) with Intel HD Graphics 4000 integrated graphics.

import java.io.IOException;
import java.nio.file.Paths;
import java.util.concurrent.ConcurrentHashMap;

import org.jsfml.graphics.*;
import org.jsfml.window.*;
import org.jsfml.window.event.Event;

public class Example {
        // Texture cache
        public static final ConcurrentHashMap<String, ConstTexture> cache =
                new ConcurrentHashMap<String, ConstTexture>();
       
        private static final String KEY = "key_string";
               
        public static void main(String[] args) {
                // Initialise window
                RenderWindow renderWindow = new RenderWindow();
                renderWindow.create(new VideoMode(800, 600), "Eg.");
               
                // On another thread, create a Texture from an image file then cache it
                Thread worker = new Thread(new Runnable() {
                        public void run() {
                                Texture texture = new Texture();
                                try {
                                        texture.loadFromFile(Paths.get("canyonlands_large.jpg"));
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                                cache.put(KEY, texture);
                        }
                });
               
                worker.start();
                               
                // Wait for the image to be loaded and
                while (worker.isAlive()) {
                        //...Show loading screen...
                }
               
                // Create a sprite using the loaded texture
                Sprite sprite = new Sprite(cache.get(KEY));
               
                // Main loop
                while (renderWindow.isOpen()) {
                        // Handle events
                        for (Event e : renderWindow.pollEvents()) {
                                if (e.type == Event.Type.CLOSED)
                                        renderWindow.close();
                        }
                       
                        // Draw sprite
                        renderWindow.clear(Color.BLACK);
                        renderWindow.draw(sprite);
                        renderWindow.display();
                }
        }
}

2
General / RenderWindow::PollEvent + mouse movement problem
« on: November 04, 2011, 08:03:00 pm »
Hi guys,

I ported the game I'm working on to SFML 2.0 today (from version 1.6) and I'm seeing a problem that was not happening before. When the mouse cursor is moved over my application's window the framerate drops noticeably and sometimes the application actually freezes while the cursor is moving (in these cases the application resumes as normal once the mouse is still again but with one really long frame).

The problem occurs regardless of whether v-sync is enabled, in both full screen and windowed modes. I'm using the latest development snapshot of SFML 2.0 (downloaded yesterday) and I have been able to reproduce this problem.

The only solution I've found is to remove the call to PollEvent from my game loop.
Before (problem occurs):
Code: [Select]
void Game::start()
{
while (pMainWindow->IsOpened())
{
// handle window events
sf::Event e;
while (pMainWindow->PollEvent(e))
{
if (e.Type == sf::Event::Closed)
{
pMainWindow->Close();
}
}

update();
draw();
}
}

After (works as normal):
Code: [Select]
void Game::start()
{
while (running)
{
update();
draw();
}
}


Without the call to PollEvent the application runs just as it did when on 1.6 (except for closing, of course). I'm wondering whether this is a bug or am I now using something incorrectly? Any suggestions would be much appreciated.

If anyone's interested here's my minimal recreation of the issue (although I've got a feeling that this would be known if it was a problem for everyone). When I run this code the speed at which the circle moves can be seen to drop whenever the mouse is over the window and is moved.

Code: [Select]
#include <SFML\Graphics.hpp>

int main()
{
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "SFML 2");
sf::Shape shape = sf::Shape::Circle(sf::Vector2f(0, 300), 40, sf::Color::Blue);

int x = 0;

while (Window.IsOpened())
{
sf::Event e;
while (Window.PollEvent(e))
{
if (e.Type == sf::Event::Closed)
{
Window.Close();
}
}

Window.Clear(sf::Color(107, 101, 237));

shape.SetX(x++ % 800);

Window.Draw(shape);
Window.Display();
}

return 0;
}

Pages: [1]
anything