Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when exiting the built HelloWorld example #12

Closed
loloof64 opened this issue Jun 6, 2018 · 14 comments
Closed

Segmentation fault when exiting the built HelloWorld example #12

loloof64 opened this issue Jun 6, 2018 · 14 comments
Labels

Comments

@loloof64
Copy link

loloof64 commented Jun 6, 2018

Hello, first congratulation for such a work and for the simplicity of your README. (The only drawback is that you don't mention the need to install the libgc-dev package).

I've built the HelloWorld sample on LinuxMint 18.3 64bit, but when exiting the application (reproduced after several compilation-launch), I get a segmentation fault. I don't know if this come from Crystal or from the qt binding

$ ./hello_world 
Invalid memory access (signal 11) at address 0x7f4459776889
[0x5aa796] *CallStack::print_backtrace:Int32 +118
[0x59f66b] __crystal_sigfault_handler +75

And again, great work.

@Papierkorb
Copy link
Owner

Hi,

  1. What hello world sample do you mean? The one in samples/ or the one in the README?
  2. Which Qt version are you on? You can either ask APT or qmake-qt5 --version.
  3. Are you using the ready-to-use branch, or have you generated the bindings yourself?
  4. Does a program work fine which just creates a Qt::Application and then exits?

@loloof64
Copy link
Author

loloof64 commented Jun 6, 2018

Hello,

  1. The hello world sample is the one in the samples subdirectory
  2. I've been installing the Qt framework with the command sudo apt-get install qtbase5-dev (and the libqt5opengl5-dev package also)
  3. I am using the master-ready-to-use branch
  4. I've been testing the following program, but I had to do CTRL+C in order to stop it, so as for now I can't give you a precise answer

The program which I've been tested just with Qt::Application.exec()

require "qt5"

# Create the application first
qApp = Qt::Application.new

# And now, start it!
Qt::Application.exec

Regards

@Papierkorb
Copy link
Owner

That behaviour is expected, as you're starting the event loop with the call to .exec. This kicks off a Qt application and will only return after it has been exited, which usually also ends the process. Just remove that line and retry.

Also, I need the Qt version that is installed, not how you installed it.

@refi64
Copy link

refi64 commented Jun 6, 2018

For future reference, the version of Qt 5 in Mint 18.3/Ubuntu Xenial is 5.5.1.

EDIT: Oh wow, I timed that comment perfectly. 👌

@Papierkorb
Copy link
Owner

@kirbyfan64 So kinda old, but the oldest version there are shipped bindings for, so that's fine. Thanks

@loloof64
Copy link
Author

loloof64 commented Jun 7, 2018

Ok : this works perfectly

require "qt5"

# Create the application first
qApp = Qt::Application.new

# And now, start it!

@Papierkorb
Copy link
Owner

Could it be that the order the finalizers are called is 'wrong'?

Try running the hello world sample without the last five lines:

# We're ready for showtime
window.show

# And now, start it!
Qt::Application.exec

I hope it still crashes?

@loloof64
Copy link
Author

loloof64 commented Jun 7, 2018

Did you mean the following ?

require "qt5"

# Create the application first
qApp = Qt::Application.new

# We'll use a normal widget as window
window = Qt::Widget.new
window.window_title = "Hello, World!"

# We need to give it a layout
layout = Qt::VBoxLayout.new
window.layout = layout

# Create a label and a button, and push it into the layout
button = Qt::PushButton.new "Click me!"
label = Qt::Label.new "Click the button!"

layout << button << label

# On every press on `button`, we want to change the label.
counter = 0

button.on_pressed do # This is how you connect to the `pressed` signal
  counter += 1
  label.text = "You pressed #{counter} times!"
end

I've just tried this code and it returns immediately without crashing (but without showing any window).

Also I build the executable with the command crystal build hello_world.cr. Maybe should I have used shard for this.

@Papierkorb
Copy link
Owner

Yes that's what I meant. Kinda sucks that it doesn't crash though. Back to square 1.

You'd have to figure out what object lies at the address given in the log in your opening post. You can do that using gdb, maybe valgrind could also help to show what's going on, etc.. But that's nothing I could give you easy directions for in terms of this issue tracker.

I assume it has something to do with the garbage collector fighting with Qt under certain circumstances. One might delete an object before the other tries to use it or deletes it too. These kind of things are time consuming to figure out (My assumption might be totally wrong!), and probably tedious to fix afterwards as well.

Sorry to bring bad news on this.

@loloof64
Copy link
Author

loloof64 commented Jun 7, 2018

Unfortunately I don't know how to use gdb nor valgrind.
Anyway thank you very much for your patience and for having trying to help me.

Regards

@refi64
Copy link

refi64 commented Jun 7, 2018

@loloof64 Try building your application in debug mode and then running valgrind path-to-my-app. Valgrind is a memory checker; it'll print out any potential wrong memory accesses.

@loloof64
Copy link
Author

loloof64 commented Jun 8, 2018

Thank you :)

$ valgrind ./hello_world 2> errors

Produced me the errors file I've attached
errors.zip

Otherwise

$ crystal run -d ./hello_world
Syntax error in hello_world:1: unknown token: '\u{7f}'

ELF�����>���Y@�lX@8
^

@docelic docelic added the bug label May 27, 2020
@docelic
Copy link
Collaborator

docelic commented May 27, 2020

This may have been solved by a temporary workaround that now exists in bindgen (added in commit Papierkorb/bindgen@01265f9 and tracked for further refinement in Papierkorb/bindgen#37)

@docelic
Copy link
Collaborator

docelic commented May 29, 2020

I am going to close this ticket since in addition to the previous comment I have also tested myself and can't reproduce the issue. Please reopen or submit a new issue if the problem persists.

@docelic docelic closed this as completed May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants