Getting screensize with ofGetScreenWidth / ofGetScreenHeight crashes

I’m trying to detect the screensize in my main.cpp to configure some objects in my application. Ideally I find a solution that works across linux/os-x and linux-arm.

With of_v0.11.2 on OS X, when I add this to main:

    int screenWidth = ofGetScreenWidth(); 
    int screenHeight = ofGetScreenHeight();

I get a crash:

ali@AlisMBP132021 MOD % make run
/bin/sh: line 1: 53499 Segmentation fault: 11  ./MOD
make: *** [run] Error 139

I’ve search the forum and the above appears to be the right way to get screen size.
Am I missing something?

Hi, that is the correct way but it will crash if you put it in main.cpp before you create the window as it depends on such.
What I would recommend is to use it in ofApp:: setup() and there apply any settings that you want need to.