Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Custom GL error? (triangle fan causes crash)
- - By RavensKrag Date 2013-12-20 03:50
Section of code that causes crash:
https://gist.github.com/RavensKrag/8050038

Dump of all the errors:
https://gist.github.com/RavensKrag/8050151

Is there some bug with custom gl code?

I just wanted to try and approximate a circle using OpenGL, so I thought I'd just whip out a triangle fan and be done with it.  Something has gone really screwy, my program seems to crash randomly. When this code is commented out, I have no problems, so it seems like the error is here somewhere.

Any ideas?
Parent - - By jlnr (dev) Date 2013-12-20 20:54
There used to be issues when Gosu put blocks in the Z queue, but the GC wanted to free them. Do the crashes stop when you disable the GC, or do they happen more often when you call GC.start? (lib/gosu.rb already tries to protect against this, though =/)

Can you attach gdb to it and see more information about the crash? The C level stack trace does not make any sense at all, why would IO.hpp be involved in GL rendering?! :)

I think it's just a matter of...

gdb ruby
run path_to_script.rb

and then backtrace when things blow up.
Parent - - By RavensKrag Date 2013-12-20 21:32
Maybe IO is involved because I'm doing some input stuff while the crash is happening? It may be an intersection of this code with some other things, but definitively, the crash goes away if I remove this code.

Strangely, disabling GC seems to have no effect (I'm using GC.disable, hopefully that's correct? Haven't done this in a while)
but forcing GC using GC.start before the block seems to eliminate the error.

Also, sometimes I just get this error, instead of a full explosion:

/home/ravenskrag/.rvm/gems/ruby-1.9.3-p448/gems/gosu-0.7.50/lib/gosu/swig_patches.rb:37:in show': method call' called on terminated object (0x0000000190cb98 flags=0x0 klass=0x0) (NotImplementedError)
  from /home/ravenskrag/.rvm/gems/ruby-1.9.3-p448/gems/gosu-0.7.50/lib/gosu/swig_patches.rb:37:in
show'
  from ./main.rb:152:in <main>'


Don't think that's very helpful though....
Will post back when I manage to get it to blow up again
(stupid sporadic errors D:)

Thanks in advance for your help :D
Parent - By jlnr (dev) Date 2013-12-26 12:16
That's interesting! Because the only object in your sample that call should be called on, are indeed the GL blocks.

So it definitely looks like a GC thing: http://stackoverflow.com/questions/2003885/garbage-collection-with-ruby-c-extension
Parent - - By RavensKrag Date 2013-12-20 21:41
Parent - - By jlnr (dev) Date 2013-12-21 09:19
Wow, that's a tough one. This stack trace "makes sense" in the way that you are not the first one to see a SIGSEGV inside st_lookup:

https://github.com/jasonroelofs/rice/issues/33

But I'm honestly clueless why only custom GL blocks would trigger this. They're not that special :)

If you are on Linux, can you retry with Ruby 2.0.0, and if your code should be compatible, also 1.8? Can you just let it run for a (long) while and it will happen?

Is your code public so that I can let it run on my Mac some time during the next days?
Parent - By RavensKrag Date 2013-12-21 19:37 Edited 2013-12-21 19:43
I thought Gosu didn't work with 2.0, but apparently I was mistaken (or it's already been fixed?).  I'll try that then.  I think I'm using a couple things that were introduced in 1.9.3, so 1.8 probably won't work (could be wrong though).

The program involves manipulating objects with the mouse.  You need to grab one of the red circles it spawns (hold right click) and then shake it violently for a few seconds.
(Weird, but rather consistent.)
Letting it sit may work, but this is my procedure for triggering the behavior.

This code will be public, but it's not on github just yet. I'll let you know when I get it up, but it could be a while, what with Christmas coming and such. It also depends on a custom input library I wrote (pure ruby, so it should run on anything) so I have to figure out if I want to vendor that through rubygems.org or just ship it through the repository for this application.

Testing with ruby 2.0 now, will report back with findings.
Parent - - By RavensKrag Date 2013-12-21 20:46
Using ruby 2.0 results in the application running for a longer period of time (not timing it, but it feels like it runs longer) but then crashing with a different error.

(some sort of error on Gosu::Text this time, rather than IO)
ruby backtrace: https://gist.github.com/RavensKrag/8074047

I'm starting to suspect that it's not actually the custom code DIRECTLY, but some weird side effect that's intersecting with other systems.
(I'm still extremely confused though.)
Parent - By jlnr (dev) Date 2013-12-26 12:20
I think it happens because this line in my GC workaround happens too early:

$gosu_gl_blocks = nil

Let me see if there is a pure-Ruby patch that you could try...
Parent - - By jlnr (dev) Date 2013-12-26 12:26
This is a hack on top of a hack; but in your gosu-0.7.50/lib/swig_patches.rb, can you change the protected_draw_2 method to...

  def protected_draw_2
    protected_draw
    $gosu_gl_blocks_2 = $gosu_gl_blocks
    $gosu_gl_blocks = nil
  end


What the current hack does is collect all gl blocks inside a global Array, which is emptied at the end of draw. But I think that's too early, because the blocks will only be disposed after draw. With the new hack, they're retained for one more frame.

If this really fixes the issue, I'll try to come up with a nicer way of doing this. :)
Parent - - By SPK Date 2013-12-26 16:04 Edited 2013-12-26 17:31
I also have problems with crashes and always thought it's ashtons fault. :P

I applied your hack and have my gl code running since 5 minutes without a crash. Looks good. I'll let it run another 30 minutes or so.

Edit: Still running like a boss. :)
Parent - - By jlnr (dev) Date 2013-12-27 00:29
Awesome! Thanks for the feedback :)
Parent - By RavensKrag Date 2014-03-25 16:57
Sorry for taking many months to respond, but I would like to confirm that this does fix my problem as well.
Up Topic Gosu / Gosu Exchange / Custom GL error? (triangle fan causes crash)

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill