openframeworks / openframeworks/openFrameworks
oF 0.8.1 ofSetupOpenGL inappropriately assumes the type of window pointer
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 9
Description
There is a block of code in ofSetupOpenGL(ofPtr<ofAppBaseWindow> windowPtr, int, int, int) that sets the OpenGL version numbers for the window pointers passed to the function. In this block of code, the type of windowPtr is assumed to be one of a few types (ofAppGLFWWindow, ofAppEGLWindow) and is casted to that type.
However, if the user is using a class inherited from ofAppBaseWindow that is not one of the assumed types, things break, badly. It's wrong to assume that a pointer to a base class is definitely one of a subset of derived classes without checking.
I see three possibilities, but there could be others:
- Maybe it's possible to move the code that sets the OpenGL version into the
setupOpenGL()functions of the app window classes that need to have the OpenGL version set to that default value. - Set the default values in
ofSetupOpenGL(int, int, int), where the user has not specified the app window to use, so you know which window type is being used (this seems like the best option to me). - Maybe give app windows a
getType()function so that it can be checked if the passed pointer is actually one of the assumed types.
The the only reason this is a problem for my use case is that ofSetupOpenGL() is the only publicly-facing way to set the window pointer static ofPtr<ofAppBaseWindow> window; declared in ofAppRunner.cpp, but used in various places through ofGetWindowPtr(). A shim that works for my use case would be to provide a function that sets the window pointer used internally.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading ofSetupOpenGL(ofPtr windowPtr, int, int, int) and the static window pointer in ofAppRunner.cpp. Trace how the function handles ofAppGLFWWindow, ofAppEGLWindow, and other ofAppBaseWindow subclasses. Done means a custom derived window no longer suffers from an invalid assumed-type cast while the intended OpenGL version behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100