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

Compatibility with SDL2 #6

Open
zacharycarter opened this issue Mar 11, 2017 · 4 comments
Open

Compatibility with SDL2 #6

zacharycarter opened this issue Mar 11, 2017 · 4 comments

Comments

@zacharycarter
Copy link

zacharycarter commented Mar 11, 2017

Hi Cory,

Zach here. Got a question for you if you have time, and reporting an issue.

I've been spending quite a bit of time playing around with these bindings and I've been encountering a lot of freezes specifically when using the SDL2 bindings.

A few notes here:

  1. I cannot get Vladar's sdl2-nim bindings working with this library with your example code on OSX. Here's output from a run on:
➜  01-Cubes git:(master) ✗ nim c -r Cubes.nim
Hint: used config file '/Users/zachcarter/projects/Nim/config/nim.cfg' [Conf]
Hint: used config file '/Users/zachcarter/projects/nim-bgfx/examples/01-Cubes/Cubes.nim.cfg' [Conf]
Hint: system [Processing]
Hint: Cubes [Processing]
Hint: bgfx [Processing]
Hint: bgfx_defines [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: algorithm [Processing]
Hint: bgfx_types [Processing]
Hint: bgfx_utils [Processing]
Hint: fpu_math [Processing]
Hint: sdl_platform [Processing]
Hint: sdl [Processing]
Hint: sdl_syswm [Processing]
Hint: bgfx_platform [Processing]
Hint: parseopt2 [Processing]
Hint: os [Processing]
Hint: times [Processing]
Hint: posix [Processing]
Hint: ospaths [Processing]
Hint:  [Link]
Hint: operation successful (35895 lines compiled; 0.949 sec total; 54.746MiB peekmem; Debug Build) [SuccessX]
Hint: /Users/zachcarter/projects/nim-bgfx/examples/01-Cubes/Cubes  [Exec]
SDL2 version: 2.0.5 - Subsystem: SYSWM_COCOA
2017-03-10 19:15:38.959 Cubes[88190:9918905] /Users/zachcarter/.nimble/pkgs/bgfx-0.2.1/embed/bgfx/src/bgfx.cpp (2565): BGFX bgfx platform data like
window handle or backbuffer must be set.
2017-03-10 19:15:38.959 Cubes[88190:9918905] /Users/zachcarter/.nimble/pkgs/bgfx-0.2.1/embed/bgfx/src/bgfx.cpp (2603): BGFX Init failed.
2017-03-10 19:15:38.959 Cubes[88190:9918905] BGFX WARN Frame buffer resolution width or height can't be larger than limits.maxTextureSize 0 (width 1
280, height 1280).

Something like - https://gist.github.com/zacharycarter/883482ee0964b317721c8aaed011b421#file-nim-bgfx-nim-L15-L45 - gets me a little further, but I still encounter errors. I can provide thread backtraces if desired.

I have gotten the official bindings working, essentially by using the code I shared above with them, but I can generate a freeze rather trivially with with a slight modification to your example code.

Have you been using these bindings in any project with SDL2 and if so, do you have any wisdom to shed on ways to avoid these freezes. I'm not sure what they're caused by, stack corruption is a guess.

Also - I've compiled BGFX in single threaded mode to reduce complexities and that still doesn't provide a solution.

Any thoughts?

Edit -

I noticed in #2 that you mention some segfaults and those are exactly what I'm encountering, but only when using SDL2. I'm leaning less towards a problem in Nim / BGFX themselves and something in the bindings leading to some sort of stack corruption maybe?

I can try to help dive into this, as I have code that easily reproduces the problem. Not sure I'm going to be able to find much though.

@auRose94
Copy link
Owner

I applied that code you showed and improved it some... same issue though. I however get a slightly different error than you. LLDB keeps preventing the exception from happening so I can't run it and get a stacktrace like I had hoped. So we got a Heisenbug.

Corys-MacBook-Pro:01-Cubes Cory$ ./Cubes
SDL2 version: 2.0.5 - Subsystem: SYSWM_COCOA
2017-03-11 23:55:18.701 Cubes[71859:7580284] /Users/Cory/.nimble/pkgs/bgfx-0.2.2/bgfx/../embed/bgfx/src/bgfx.cpp (2591): BGFX Init...
2017-03-11 23:55:18.701 Cubes[71859:7580284] /Users/Cory/.nimble/pkgs/bgfx-0.2.2/bgfx/../embed/bgfx/src/bgfx.cpp (1321): BGFX Creating rendering thread.
2017-03-11 23:55:18.701 Cubes[71859:7580284] /Users/Cory/.nimble/pkgs/bgfx-0.2.2/bgfx/../embed/bgfx/src/bgfx.cpp (1330): BGFX Running in multi-threaded mode
2017-03-11 23:55:18.701 Cubes[71859:7580313] /Users/Cory/.nimble/pkgs/bgfx-0.2.2/bgfx/../embed/bgfx/src/bgfx_p.h (2215): BGFX render thread start
Traceback (most recent call last)
Cubes.nim(155) Cubes
sdl_platform.nim(69) StartExample
bgfx.nim(115) Start
bgfx.nim(116) Init
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

I actually didn't try SDL with bgfx on OS X except for just recently. I was able to get a barebones engine running on linux successfully. But then got unsuccessful results on OS X like you. If you could give me more info with the latest commit that would be awesome.

@zacharycarter
Copy link
Author

Hmm, sorry I wasn't clear enough in my original post.

That code is only necessary in order to get the official Nim SDL bindings to work. I do get the same error as you with the latest commit when using the same bindings (Vladars) as in the examples.

I'm really not sure how to get Vladar's bindings working on OSX. The problem as I see it is this : https://github.com/Vladar4/sdl2_nim/blob/952d0fe5afb62236cf4ccad4bba7b52193e85bfd/sdl2/sdl_syswm.nim#L214

I have no idea where NSWindow is supposed to come from, when that define is satisfied.

The code I posted, does work with the official SDL2 bindings or at least it gets them to work with these bindings. The only problem then is all the freezes I mentioned above.

If you'd like, I can submit a PR and get things working with the examples with the official bindings. Or we can keep working at getting Vladar's bindings working.

@auRose94
Copy link
Owner

I actually need to catch up on some work I have and can't fix this right now. You can send a pull request and do whatever is necessary for SDL2 to work on OS X. You can also try using the official Nim bindings for SDL2 if you think you can get it working.

I will try fixing this later when I have the time.

@zacharycarter
Copy link
Author

I'm convinced something is up with the C++ emits. I don't have time to debug this at the moment either - I've created my own bindings and users will just have to dynamically link to the BGFX C API. I have things working on Arch Linux, OSX and Android. Ubuntu is causing problems due to linking order, but I'd rather tackle that challenge than try to figure out what is going on with the freezes with the C++ API.

Hopefully you or someone else gets this sorted out and I can resume using these bindings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants