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

Author Topic: rbSFML  (Read 159633 times)

0 Members and 4 Guests are viewing this topic.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #165 on: April 20, 2012, 06:06:02 pm »
The thing is that I am kind of mimicking how C++ works with the rect. So either you give Floats or Fixnums to the rect.

I am at a loss at what to do here. As in Ruby nothing is implicitly converted you have to explicitly do it with the #to_* methods. But on the other hand most of the number classes can be used with each other seamlessly.

What do you feel would be most convenient?

And to quickly solve your problem: Rect's don't accept different types in their arguments as of now.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

vivo

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
    • Email
Re: rbSFML
« Reply #166 on: April 20, 2012, 06:13:14 pm »
http://en.sfml-dev.org/forums/index.php?topic=3879.msg33533#msg33533

After some quick searching in Google for a solution to the problem I actually got a good link back to SFML here ^^
Seems it is a driver issue and probably upgrading will help you out. If that doesn't fix it I guess you can still work with this as long as your application don't crash :)
Or well until the window is closed. It seems the error is triggered by that.
Yes, I have a ATI Mobility Radeon HD serios 5xxx too. So probably is the same problem, my fglrx (ATI debian drivers) are updated, I will try with a better conexion to do an apt-get update for all

One question besides all this, wich editor are you using for rbSFML?
I'm using vim, but I'd like to try another editor with code intelligence (autocompletion, go to definition, etc..)

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #167 on: April 20, 2012, 06:16:59 pm »
I like Geany but I am currently trying out Redcar which itself is written in Ruby as well. And it seems to be working out pretty well even though it is not in a finished state yet.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

vivo

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
    • Email
Re: rbSFML
« Reply #168 on: April 20, 2012, 06:24:13 pm »
thanks, I'll try Geany then.

This is the output when I disable raise_exceptions, looks better
Failed to load image "cute_image2.jpg". Reason : Unable to open file
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server "��                @n"
      after 6374 requests (6373 known processed) with 0 events remaining.
AL lib: ALc.c:1420: alcDestroyContext(): deleting 1 Source(s)
AL lib: ALc.c:1818: alcCloseDevice(): deleting 3 Buffer(s)
ruby: /build/buildd/openal-soft-1.12.854/OpenAL32/Include/alMain.h:75: EnterCriticalSection: Assertion `ret == 0' failed.
Abortado


Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: rbSFML
« Reply #169 on: April 20, 2012, 06:29:53 pm »
Should it work when I exclusively give floats as arguments? Both these lines give the same error as before:
bar = SFML::Rect.new(0.5, 0.5, 1.to_f, 1.to_f)
bar = SFML::Rect.new(0.5, 0.5, 1.0, 1.0)
I think the type of number shouldn't matter in this case. Usually floats, bignums and fixnums can be used exchangeable, so they should be here as well. I personally think the code I posted looks valid (to me at least) and should therefore work (or, as it's called in the programmer's guide, it should follow the "Principle of Least Surprise". Not being able to use one type of number was a surprise for me). It doesn't feel consistent right now.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #170 on: April 20, 2012, 06:40:05 pm »
Alright, I'll fix rect as soon as I get home. And it looks like there is a problem in the audio module. Can I get your code that causes the abortion so I can check if something is wrong on my end.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

vivo

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
    • Email
Re: rbSFML
« Reply #171 on: April 20, 2012, 06:55:10 pm »
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
# Include the RubySFML extension
#require 'sfml/system'
#require 'sfml/window'
#require 'sfml/audio'
#require 'sfml/graphics'
    Kernel.require( 'sfml/all' )
    Kernel.require( 'logger' )
include SFML

def create_texture_from_file file
        begin
                texture = Texture.new(file)
                return texture
        rescue
                #texture = Texture.new(100,100)
                puts("Error loading texture from file #{file}")
                return false
        end    
end    
SFML.raise_exceptions = false
 #    // Create the main window
#    sf::RenderWindow
        vm = VideoMode.new(800,600,32)
        window = RenderWindow.new(vm, "SFML window")
 
 #    // Load a sprite to display
#     sf::Texture texture;
        texture = Texture.new('cute_image2.jpg')
#if(!texture = create_texture_from_file('cute_image2.jpg'))
#       raise "I throw an exception"
#       #exit!
#end

     if (!texture)
        return SystemExit#success?
end
      sprite = Sprite.new(texture);
#       sprite.setTexture(texture)
 
 #   // Create a graphical text to display
#     sf::Font font;
        font = Font.new()
#     if(!font.loadFromFile("arial.ttf"))
font = Font::getDefaultFont()    
   #return EXIT_FAILURE;
   
#       end
 text = Text.new("Hello SFML");
text.setFont(font)
text.setCharacterSize(50);
 
 #   // Load a music to play
#     sf::Music music;
        music = Music.new
     if (!music.openFromFile("nice_music.ogg"))
         return EXIT_FAILURE;
        end
 #   // Play the music
     music.play();
 
 #   // Start the game loop
     while (window.isOpen())
 #       // Process events
         #sf::Event event;
        event = Event.new()
         while (window.pollEvent(event))
 #           // Close window : exit
             if (event.type == Event::Closed)
                 window.close();
                end
        end
 #       // Clear screen
         window.clear();
 
 #       // Draw the sprite
        window.draw(sprite);
 
 #       // Draw the string
         window.draw(text);
 
 #       // Update the window
         window.display();
        end
     return EXIT_SUCCESS;
 

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #172 on: April 20, 2012, 09:10:34 pm »
Alright up and running with Rect and I don't really know what's causing your problem with OpenAL. Seems like Linux like playing around with my stuff... Have you tested a C++ application and see what happens yet? Remember to link against sfml-audio as well.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: rbSFML
« Reply #173 on: April 20, 2012, 10:19:19 pm »
I tried out the audio package as well, and found another mystifying thing: When calling a non existent method on a SFML::Music object the program crashes. Not just a simple "undefined method" error, but a full "Ruby interpreter has stopped working" error message. No other classes seem to have this behavior. Playing music seems to work fine for me though (when using the right method).

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #174 on: April 20, 2012, 10:39:03 pm »
That is strange indeed and shouldn't be possible. I'll have a look at it.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: rbSFML
« Reply #175 on: April 21, 2012, 11:51:07 am »
It appears to be impossible to create a new render state. Or am I doing something wrong?
Code: [Select]
irb(main):009:0> state = SFML::RenderStates.new
RuntimeError: can't modify frozen SFML::Transform

Edit: Also, the PrimitiveTypes for drawing vertices don't appear to make sense. They contain 0, 1, 2, true, false, nil and SFML::Quads isn't initialized.
Code: [Select]
irb(main):014:0> puts SFML::Lines
0
=> nil
irb(main):015:0> puts SFML::Points
false
=> nil
irb(main):016:0> puts SFML::LinesStrip
true
=> nil
irb(main):017:0> puts SFML::Triangles
1
=> nil
irb(main):018:0> puts SFML::TrianglesStrip

=> nil
irb(main):019:0> puts SFML::TrianglesFan
2
=> nil
irb(main):020:0> puts SFML::Quads
NameError: uninitialized constant SFML::Quads
        from (irb):20
        from C:/Ruby193/bin/irb:12:in `<main>'
« Last Edit: April 21, 2012, 11:59:05 am by Lupinius »

vivo

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
    • Email
Re: rbSFML
« Reply #176 on: April 21, 2012, 01:46:05 pm »
well, heres is the output for a test.cpp and linking with audio and graphics

Any error, besides the expected "could'nt find the file"

gcc graph.o -o test -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system
vivo@ubuntu:~/Escritorio/proyectoAG/primer_juego$ ./test
Failed to load image "cute_image". Reason : Unable to open file
 

This takes me to thing that the problem comes for an unhandled exception in ruby (maybe in windows doesn't mather this, but x-konsole shows the error). If you remember, when I handled the exception the program didn't crash.

    Kernel.require( 'sfml/all' )
include SFML

def create_texture_from_file file
        begin
                texture = Texture.new(file)
                return texture
        rescue
                #texture = Texture.new(100,100)
                puts("Error loading texture from file #{file}")
                return false
        end
end

if(!texture = create_texture_from_file('cute_image2.jpg'))
#       raise "I throw an exception"
#        return -1
Kernel.exit!
end
 


if I uncomment raise line-> crashes
if I uncomment return line-> crashes
if I uncomment exit line-> exit is: Error loading texture from file

The return line in mi mind represents whats happening now at now, letting the c++ SFML behabior for handle the exception, probably returning some value
« Last Edit: April 21, 2012, 04:22:15 pm by vivo »

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #177 on: April 21, 2012, 05:12:11 pm »
Alright fixed the bug with BlendModes, PrimitiveTypes and RenderStates. Most of these bugs have been simple mistakes which comes from that I had to write a lot of code under little time ^^

Anyway the Linux problem I am kind of lost at. Did you try to mimic the ruby code in C++? Keep in mind that everything in Ruby is allocated on the heap so you have to use the new keyword. And check what happens if you ignore deleting and what if you delete. Can you also try and find out when in the application the error messages are put out? Like during the application runs or when it exists? Can you try and invoke the garbage collector while running and see what happens then?

The only thing I can find that is causing this is that I somehow isn't handling the Ruby memory correctly or something. Since I am using SFML code in the code so it has to be something there in-between.

I created a new branch called "linux_fix" which doesn't use Ruby's heap to allocate objects. See if this works better for you.
« Last Edit: April 21, 2012, 05:24:55 pm by Groogy »
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

vivo

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
    • Email
Re: rbSFML
« Reply #178 on: April 21, 2012, 05:45:31 pm »
Anyway the Linux problem I am kind of lost at. Did you try to mimic the ruby code in C++? Keep in mind that everything in Ruby is allocated on the heap so you have to use the new keyword.
I don't understand what you want to mean with mimic the ruby code, sorry

I created a new branch called "linux_fix" which doesn't use Ruby's heap to allocate objects. See if this works better for you.
Thanks, I'll check it in advance
For the moment, as far as the problem only occurs with exceptions, I can keep working


vivo

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
    • Email
Re: rbSFML
« Reply #179 on: April 21, 2012, 05:59:22 pm »
More reports:

No method Texture.loadFromImage (like loadFromFile)

I guess alias is not implemented yet


[attachment deleted by admin]