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

Author Topic: Framebuffer crash  (Read 6702 times)

0 Members and 1 Guest are viewing this topic.

Evan Bowman

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Framebuffer crash
« on: February 02, 2017, 04:46:22 pm »
Hi,

I started doing a project that uses OpenGL for graphics, and the SFML Window module to create a gl context for rendering.

I got to a point in the project where I want to do some shadow mapping, which generally involves encoding fragment depth info in a framebuffer object, and then using that data for occlusion.

I'm having an issue though where when I bind a framebuffer for depth rendering and then switch back to the default framebuffer and call glClear(...), macOS goes into a kernel panic.

I've included a minimal example below that reproduces the problem, it's about 60 lines of code, and when compiled and run in isolation my OS dies.  I've annotated the line where the crash happens, somewhere within the call to the glClear library function. Most of what I'm doing feels pretty harmless, so I'm not sure whether I've made a huge mistake somewhere or if this is some SFML bug.

Code:
(click to show/hide)
« Last Edit: February 02, 2017, 05:13:39 pm by Evan Bowman »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Framebuffer crash
« Reply #1 on: February 03, 2017, 01:24:16 am »
So how does "my OS dies" look like? Does macOS have graphics drivers that need to be installed?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Evan Bowman

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Re: Framebuffer crash
« Reply #2 on: February 03, 2017, 02:47:21 am »
So how does "my OS dies" look like? Does macOS have graphics drivers that need to be installed?

I mean I get the dreaded multilingual kernel panic screen  :-\. In macOS drivers are supposed to be pre-installed, but that's a thing to check.

I have no problem using most OpenGL functionality in an SFML window, it's only when I render to an offscreen framebuffer and then switch back that I get this problem.

One thing that I am thinking of trying is to write up an analogous program in glfw/sdl and see if that crashes, it would help determine whether or not this is an SFML issue. I just wanted to see if anyone had any other ideas before I went to the trouble of doing that.
« Last Edit: February 03, 2017, 02:51:39 am by Evan Bowman »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Framebuffer crash
« Reply #3 on: February 03, 2017, 03:11:13 am »
Maybe it's related to this issue? What's your SFML version?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Evan Bowman

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Re: Framebuffer crash
« Reply #4 on: February 03, 2017, 03:57:18 am »
Maybe it's related to this issue? What's your SFML version?

I use the latest stable release, and the latest version of macOS. I can create and draw to render textures just fine, but maybe it's related. After doing some digging in the filesystem I've found my kernel panic report and power usage info. The top of the call stack lists my graphics driver as a dependency, but I'm not sure whether that points to an issue with the driver itself or a problem with how my executable is using the driver. I'm going to try reinstalling it.

EDIT:
The graphics driver is only packaged with the operating system so I can't easily replace it. I'm going to run an update and see if it helps.

(click to show/hide)
« Last Edit: February 03, 2017, 04:02:42 am by Evan Bowman »

Evan Bowman

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Re: Framebuffer crash
« Reply #5 on: February 03, 2017, 06:52:36 am »
Ok so this is bizarre, but I've found that adding these lines:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_window.display();
 

at least once (e.g. in the constructor for my application), before attempting to render to an offscreen gl framebuffer object prevents the kernel panics. This is weird behavior to me, could it be a bug with SFML?

Evan Bowman

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Re: Framebuffer crash
« Reply #6 on: February 03, 2017, 07:29:48 am »
Ok so this is bizarre, but I've found that adding these lines:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_window.display();
 

at least once (e.g. in the constructor for my application), before attempting to render to an offscreen gl framebuffer object prevents the kernel panics. This is weird behavior to me, could it be a bug with SFML?

Also I just realized that if I'm going to do this, I also need to run one pass through the SFML Event loop first or I could get segfaults.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Framebuffer crash
« Reply #7 on: February 03, 2017, 11:50:57 am »
Running 10.11.6 here, all security patches installed (which is the way to get drivers updates), and a recent master version of SFML, but no kernel panic nor crash with the initial code posted. Only this (expected) output:

$ clang++ test.cpp -framework sfml-system -framework sfml-window -framework OpenGL
$ ./a.out
Warning. Compatibility profile not supported on this platform.
Error. Unable to create the context. Retrying without shared context.
Warning. New context created without shared context.
Warning: The created OpenGL context does not fully meet the settings that were requested
Requested: version = 4.1 ; depth bits = 32 ; stencil bits = 8 ; AA level = 4 ; core = false ; debug = false ; sRGB = false
Created: version = 4.1 ; depth bits = 32 ; stencil bits = 8 ; AA level = 4 ; core = true ; debug = false ; sRGB = false
SFML / OS X developer

Evan Bowman

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Re: Framebuffer crash
« Reply #8 on: February 03, 2017, 03:19:54 pm »
Running 10.11.6 here, all security patches installed (which is the way to get drivers updates), and a recent master version of SFML, but no kernel panic nor crash with the initial code posted.

I appreciate you taking the time to look into this. This seems like it may be some localized problem that I'm having, I'll try doing that security patch. It's reassuring to hear that the sample code I posted is working for you, because I had looked over it so many times and it was driving me crazy that I couldn't find a problem with it. Thanks for your help, both of you!