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 - MorleyDev

Pages: [1]
1
Graphics / Asynchronous loading of textures causes Stack Overflow
« on: January 27, 2016, 10:02:47 pm »
The following code, which is my attempt at recreating the issue, appears to cause a stack overflow with the latest version of master of SFML (Debug or Release) in Visual Studio 2015. It also seems to crash gcc version 5.2.0 (x86_64-posix-seh-rev1, Built by MinGW-W64 project).

Loading with std::launch::deferred (So single-threaded) does not appear to cause any issue, suggesting it's a multithreading-exclusive issue.

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <future>

int main() {

        sf::RenderWindow window(sf::VideoMode(320, 240), "Possible bug with multithreading");
        std::shared_ptr<sf::Texture> texture = std::async(std::launch::async, []() -> std::shared_ptr<sf::Texture> {
                std::shared_ptr<sf::Texture> result = std::make_shared<sf::Texture>();
                if (!result->loadFromFile("simple.png")) { // <-- this line causes a crash
                        return nullptr;
                }
                return result;
        }).get();

        if (!texture) {
                return -1;
        }

        sf::Sprite sprite;
        sprite.setTexture(*texture);
        sprite.setPosition(sf::Vector2f(0.0, 0.0));

        while (true) {
                window.draw(sprite);
                window.display();

                sf::Event event;
                while (window.pollEvent(event)) {
                        if (event.type == sf::Event::Closed) {
                                return 0;
                        }
                }
        }
}
 

Battling the visual studio debugger would make it look like the code is repeatedly jumping in SFML between four functions:
    sfml-window-d-2.dll!`anonymous namespace'::getInternalContext() Line 155   C++
    sfml-window-d-2.dll!sf::priv::GlContext::ensureContext() Line 213   C++
    sfml-window-d-2.dll!sf::GlResource::GlResource() Line 61   C++
    sfml-window-d-2.dll!sf::Context::Context() Line 61   C++
And this endless recursive loop leads to stack overflow. gdb gives similar output when running 'where' after the segmentatiom fault.

It seems the newing up of a ThreadLocal sf::Context is triggering a call to getInternalContext, which then sees there is no internal context, so it then news up an sf::Context, which calls getInternalContext, which then goes on ad infinitum.

Is multithreaded texture creation currently broken? It's something I can imagine not being too rare a use-case, wanting to load assets in a separate thread from the main.

2
#include <SFML/Audio.hpp>
#include <SFML/System/FileInputStream.hpp>
#include <iostream>
#include <cstdio>

int main() {
    std::cout << "Starting..." << std::endl;
    sf::Music fileMusic;
    if (!fileMusic.openFromFile("sample.ogg")) {
        std::cerr << "Too early boom?"  << std::endl;
        return 3;
    }

    sf::Music music;
    sf::FileInputStream stream;
    if (!stream.open("sample.ogg")) {
        std::cerr << "Too early boom?"  << std::endl;
        return 2;
    }
    if (!music.openFromStream(stream)) {
        std::cerr << "BOOM!"  << std::endl;
        return 1;
    }
    std::cout << "Done" << std::endl;
    return 0;
}

 

sample.ogg is orchestra.ogg from the examples folder.

Loading from a file works, but trying to load music from an InputStream seems to fail. Am I doing something wrong, or has this broken on master? This used to work until I updated to the latest master.

3
Feature requests / Setup an official AppVeyor/Travis-CI for SFML?
« on: March 10, 2015, 11:16:42 pm »
So my building of SFML stopped working for some reason. Originally I feared it was broken by a recent commit, but I created an AppVeyor pointing at SFML and it built: https://ci.appveyor.com/project/MorleyDev/sfml/build/1.0.1

Normally I'd fix the issue with my machine and move on with my life, but I want to use this as an opportunity to raise that it may be time to establish official automated builds on Windows  through something like AppVeyor for SFML's master branch (and Linux through Travis-CI?).

This is useful to sanity check building doesn't fall down, and also acts as something to point to if this happens to someone else.

4
SFML projects / FlapBoy [#gbjam3] [Flappy Bird Clone]
« on: August 07, 2014, 03:59:23 pm »
A Flappy Bird clone I made for the #gbjam3, the game is written in C++ using SFML. Supports multiple difficulty modes. Don't hit the pipes or leave the screen. Basically an excuse to play around with some game architecture ideas. And because I figured I was possibly the last programmer on the planet who hadn't cloned Flappy Bird yet.

Screenshots


Videos
http://youtu.be/h95dDfqzc_c

Default controls
InGame:
- W: Jump
- Escape: Return To Menu
- P: Toggle Debug View

In Start Menu:
- W: Change Menu Option
- D: Change Difficulty
- Enter: Select Menu Option
Close the window or choose "Quit Game" from the menu to quit.

Download
GameJolt Page to Download
To run, launch FlapBoy.cmd

5
Ghost Hunt - Multiplayer Prototype
Download Link
Source Code (Git Repository)

Description
Written for university coursework, this is a multi-player game modeled after Pac-Man where the player and ghosts are all human players. The game is written in Scala using JSFML for graphics and audio. To run, download, unzip and launch either the ghosthunt shell script or the ghosthunt.bat batch file in the bin directory.

Controls
In-Game
- W = Move Up
- A = Move Left
- S = Move Right
- D = Move Down

In-Menu
- Mouse Click = Select a menu item (text boxes, buttons, etc.)
- Keyboard = Typing for Host and Port

Goals
The goals of the 'Hero' are to collect all the pellets and avoid the ghosts.
The goal of the ghosts are to hound and catch the player.

Known Issues
Gameplay
- It is possible for the ghosts to make victory impossible for the player by simply not moving, as this means they'll remain covering a pellet.
- It is difficult for the player to lose the ghosts when they are detected, as they have no means of repelling or escaping except for moving around the maze.
- Gameplay with only 2 players is boring.
- Players can't decide whether to be ghosts or the hero, the server automatically assigns those.
- Players can't start a game, the "Start Game" button is on the host window and must be clicked by whoever is running the host.

Technical
- If the hero disconnects, then two hero characters will be displayed on screen when the server returns to the lobby and in the next game.

Screenshots



Credits
FilenameTitleArtistLicenseSource
font.ttfSensationBernd MontagFreewarehttp://www.dafont.com/sansation.font
title.oggWingsHalcyonic Falcon Xhttp://creativecommons.org/publicdomain/zero/1.0/http://open.commonly.cc/
game.oggThose Of Us Who FightHalcyonic Falcon Xhttp://creativecommons.org/publicdomain/zero/1.0/http://open.commonly.cc/
endgame.oggThat Which We Have Lost And ForgottenHalcyonic Falcon Xhttp://creativecommons.org/publicdomain/zero/1.0/http://open.commonly.cc/
player_death.oggShot Gun Soundluminalacehttp://creativecommons.org/licenses/by/3.0/http://soundbible.com/1706-Shot-Gun.html
beep.oggbeepCHydranoshttp://creativecommons.org/publicdomain/zero/1.0/http://www.freesound.org/people/Hydranos/sounds/237706/




Hello, I figured I'd post this here. I made this casually in about a week fairly easily using Scala and JSFML, with the networking code going through Java sockets, for my coursework. Having now more-or-less graduated (still got to get the ceremony), I figured I'd share it around a little before it vanishes into the aether. I got an A for this, don't ask me how.

But I do like the core gameplay idea, so am toying with porting it over to something a bit more portable, making it less obvious a pacman clone, improving the assets (I made the graphics, the graphics suck), fixing the issues with the gameplay, implementing AI to allow for single-player or for game-play with 2 players to be enjoyable. I want to know if people think that's a good idea or not.

6
Hello. So I want to make sure this isn't me doing something stupid or previously mentioned before I open an issue on it.

The following code will run on Linux perfectly, but on Windows (using the nuwen distribution of MinGW) the code compiles but crashes when trying to deserialise the string from the code. Changing it to a sf::String works, so that's a potential workaround. std::wstring will crash too, despite the documentation listing it as supported.

#include <SFML/Network.hpp>
#include <cstdint>
#include <iostream>
#include <stdexcept>

inline std::uint16_t getFreePort()
{
        sf::TcpListener listener;
        listener.listen(sf::TcpListener::AnyPort);
        return listener.getLocalPort();
}
       
int main(int nArgs, char** ppcArgs)
{
        typedef std::string PacketData;
        auto generatePacketData = []() { return PacketData("Hello_World"); };
        auto printPacketData = [](std::ostream& stream, PacketData data) { stream << data; };
       
        const auto port = getFreePort();
        const std::string ip = "127.0.0.1";
       
        std::cout << "Listener listens" << std::endl;
        sf::TcpListener listener;
        if ( listener.listen(port) != sf::Socket::Status::Done )
                throw std::runtime_error("Could not listen on port " + std::to_string(port));
        listener.setBlocking(false);
       
        std::cout << "Client Socket Connects" << std::endl;
        sf::TcpSocket clientSocket;
        if ( clientSocket.connect(sf::IpAddress(ip), port) != sf::Socket::Status::Done )
                throw std::runtime_error("Could not connect to listener on port " + std::to_string(port));
        clientSocket.setBlocking(false);

        std::cout << "Waiting for networking overhead" << std::endl;
        sf::sleep(sf::seconds(1));
       
        std::cout << "Server accepts" << std::endl;
        sf::TcpSocket serverSocket;
        if ( listener.accept(serverSocket) != sf::Socket::Status::Done )
                throw std::runtime_error("Could not accept listener on port " + std::to_string(port));
        serverSocket.setBlocking(false);
       
        const PacketData inData = generatePacketData();
       
        std::cout << "Client sends packet" << std::endl;
        sf::Packet sendPacket;
        sendPacket << inData;
        clientSocket.send(sendPacket);
       
        std::cout << "Server receives packet" << std::endl;
        sf::Packet receivePacket;
        const auto status = serverSocket.receive(receivePacket);
       
        PacketData outData;
        switch(status)
        {
        case sf::Socket::Status::Done:
                std::cout << "Server received packet" << std::endl;
                receivePacket >> outData;
                std::cout << "Server clears packet" << std::endl;
                receivePacket.clear();
                break;

        default:
                throw std::runtime_error("Did not receive packet");
        }
       
        std::cout << "Received packet: ";
        printPacketData(std::cout, outData);
        std::cout << std::endl;
       
        return 0;
}
 

Am I missing something obvious, is std::string/std::wstring not supported with sf::Packet and it crashes or just works because of some overloading nonsense, or is it a known (or unknown) bug in sf::Packet?

Whilst I can use the sf::String solution, a compiler error would of been be nicer than my roundtrip tests of my SFML wrappers crashing (not failing, just straight up crashing) and me having to break out the debugger because of this unintuitive gotcha in SFML's packets.

7
Network / Http networking lacks Put and Delete method support?
« on: July 17, 2012, 03:01:49 pm »
I was looking through SFML's HTTP documentation for 2.0 and noticed the list of supported request methods included GET, POST and HEAD. However, it seems there is no mention of PUT and DELETE.

I would of had use of these methods due to working on some code where I wanted to use a third party web service is using a REST design, tying specific functionality to them and letting you perform operations on an account in their database.

So, basically I'm curious: Why no put or delete? Or am I just blind?

Pages: [1]
anything