Skip to content

Commit

Permalink
Back out most of the debug output code. Throw some exceptions when fa…
Browse files Browse the repository at this point in the history
…iling to connect to the X server.
  • Loading branch information
codereader committed Apr 24, 2021
1 parent a639b36 commit f4d2416
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 170 deletions.
8 changes: 4 additions & 4 deletions radiantcore/log/LogStream.cpp
Expand Up @@ -42,18 +42,18 @@ void LogStream::InitialiseStreams(ILogWriter& logWriter)
GlobalErrorStream().setLock(logWriter.getStreamLock());
GlobalDebugStream().setLock(logWriter.getStreamLock());

#if !defined(POSIX) || !defined(_DEBUG)
#if !defined(POSIX) && !defined(_DEBUG)
// Redirect std::cout to the log, except on Linux debug builds where
// logging to the console is more useful
//COutRedirector::init(logWriter);
COutRedirector::init(logWriter);
#endif
}

void LogStream::ShutdownStreams()
{
#if !defined(POSIX) || !defined(_DEBUG)
#if !defined(POSIX) && !defined(_DEBUG)
// Stop redirecting std::cout
//COutRedirector::destroy();
COutRedirector::destroy();
#endif
}

Expand Down
80 changes: 0 additions & 80 deletions test/ConsoleLogger.h

This file was deleted.

91 changes: 35 additions & 56 deletions test/HeadlessOpenGLContext.cpp
Expand Up @@ -123,78 +123,56 @@ class HeadlessOpenGLContext :
GLXPbuffer _pixelBuffer;

public:
HeadlessOpenGLContext() :
_context(nullptr),
_pixelBuffer(0)
{
auto glxcfbconfig = (PFNGLXCHOOSEFBCONFIGPROC)glXGetProcAddress((GLubyte*)"glXChooseFBConfig");
auto glxcreatenewctx = (PFNGLXCREATENEWCONTEXTPROC)glXGetProcAddress((GLubyte*)"glXCreateNewContext");
auto glxcreatepixelbuffer = (PFNGLXCREATEPBUFFERPROC)glXGetProcAddress((GLubyte*)"glXCreatePbuffer");
auto glxmakecurrent = (PFNGLXMAKECONTEXTCURRENTPROC)glXGetProcAddress((GLubyte*)"glXMakeContextCurrent");

auto displayName = strenv("DISPLAY");

std::cout << "DISPLAY environment variable = '" << displayName << "'" << std::endl;

if (displayName.empty())
{
displayName = ":1";
std::cout << "Using fallback value DISPLAY = '" << displayName << "'" << std::endl;
}
HeadlessOpenGLContext() :
_context(nullptr),
_pixelBuffer(0)
{
auto glxcfbconfig = (PFNGLXCHOOSEFBCONFIGPROC)glXGetProcAddress((GLubyte*)"glXChooseFBConfig");
auto glxcreatenewctx = (PFNGLXCREATENEWCONTEXTPROC)glXGetProcAddress((GLubyte*)"glXCreateNewContext");
auto glxcreatepixelbuffer = (PFNGLXCREATEPBUFFERPROC)glXGetProcAddress((GLubyte*)"glXCreatePbuffer");
auto glxmakecurrent = (PFNGLXMAKECONTEXTCURRENTPROC)glXGetProcAddress((GLubyte*)"glXMakeContextCurrent");

std::cout << "XOpenDisplay..." << std::endl;
auto displayName = strenv("DISPLAY");

_display = XOpenDisplay(displayName.c_str());

std::cout << "XOpenDisplay returned: " << _display << std::endl;

static int pixelFormat[] = { GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, None };

int glx_major, glx_minor;
if (!glXQueryVersion(_display, &glx_major, &glx_minor))
{
std::cerr << "glXQueryVersion failed" << std::endl;
throw new std::runtime_error("Failed to query GLX version");
}
if (_display == nullptr)
{
throw std::runtime_error("Failed to open X display, DISPLAY environment variable is set to '" + displayName + "'");
}

std::cout << "GLX version: " << glx_major << "." << glx_minor << std::endl;
static int pixelFormat[] = { GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, None };

int glx_major, glx_minor;
if (!glXQueryVersion(_display, &glx_major, &glx_minor))
{
throw std::runtime_error("Failed to query GLX version");
}

std::cout << "glxcfbconfig..." << std::endl;
rMessage() << "GLX version: " << glx_major << "." << glx_minor << std::endl;

int configs = 0;
int configs = 0;
_fbConfigs = glxcfbconfig(_display, DefaultScreen(_display), 0, &configs);

std::cout << "glxcreatenewctx..." << std::endl;

_context = glxcreatenewctx(_display, _fbConfigs[0], GLX_RGBA_TYPE, None, True);

std::cout << "glxcreatepixelbuffer..." << std::endl;
_context = glxcreatenewctx(_display, _fbConfigs[0], GLX_RGBA_TYPE, None, True);

// Create a dummy pbuffer. We will render to framebuffers anyway, but we need a pbuffer to
// Create a dummy pbuffer. We will render to framebuffers anyway, but we need a pbuffer to
// activate the context.
int pixelBufferAttributes[] = { GLX_PBUFFER_WIDTH, 8, GLX_PBUFFER_HEIGHT, 8, None };
_pixelBuffer = glxcreatepixelbuffer(_display, _fbConfigs[0], pixelBufferAttributes);

std::cout << "glxmakecurrent..." << std::endl;

// try to make it the current context
if (!glxmakecurrent(_display, _pixelBuffer, _pixelBuffer, _context))
{
std::cout << "1st glxmakecurrent failed..." << std::endl;

// some drivers does not support context without default framebuffer, so fallback on
// using the default window.
if (!glxmakecurrent(_display, DefaultRootWindow(_display), DefaultRootWindow(_display), _context))
{
std::cout << "2nd glxmakecurrent failed..." << std::endl;

rError() << "Failed to make current" << std::endl;
throw new std::runtime_error("Failed to make current");
}
{
// some drivers does not support context without default framebuffer, so fallback on
// using the default window.
if (!glxmakecurrent(_display, DefaultRootWindow(_display), DefaultRootWindow(_display), _context))
{
rError() << "Failed to make current" << std::endl;
throw std::runtime_error("Failed to make current");
}
}

std::cout << "HeadlessOpenGLContext done." << std::endl;
}
}

~HeadlessOpenGLContext()
{
Expand Down Expand Up @@ -230,7 +208,8 @@ void HeadlessOpenGLContextModule::createContext()
}
catch (const std::runtime_error& ex)
{
std::cerr << "Headless GL context creation failed: " << ex.what() << std::endl;
rError() << "Headless GL context creation failed: " << ex.what() << std::endl;
std::cerr << "Headless GL context creation failed: " << ex.what() << std::endl;
}
}

Expand Down
30 changes: 0 additions & 30 deletions test/RadiantTest.h
Expand Up @@ -11,7 +11,6 @@

#include "TestContext.h"
#include "TestLogFile.h"
#include "ConsoleLogger.h"
#include "HeadlessOpenGLContext.h"
#include "module/CoreModule.h"
#include "messages/GameConfigNeededMessage.h"
Expand All @@ -20,17 +19,6 @@
namespace test
{

namespace
{
// Get an environment variable as a string (because getenv() can return nullptr
// and it is not safe to construct a string from a nullptr)
inline std::string strenv(const std::string& key)
{
const char* v = getenv(key.c_str());
return v ? std::string(v) : std::string();
}
}

/**
* Test fixture setting up the application context and
* the radiant core module.
Expand All @@ -51,7 +39,6 @@ class RadiantTest :
std::shared_ptr<gl::HeadlessOpenGLContextModule> _glContextModule;

std::unique_ptr<TestLogFile> _testLogFile;
std::unique_ptr<ConsoleLogger> _consoleLogger;

protected:
RadiantTest()
Expand Down Expand Up @@ -105,30 +92,19 @@ class RadiantTest :

try
{
std::cout << "Entering core module startup" << std::endl;

// Startup the application
_coreModule->get()->startup();

std::cout << "Core module startup done" << std::endl;
}
catch (const radiant::IRadiant::StartupFailure & ex)
{
// An unhandled exception during module initialisation => display a popup and exit
rError() << "Unhandled Exception: " << ex.what() << std::endl;
std::cout << "Unhandled Exception: " << ex.what() << std::endl;
abort();
}

std::cout << "Creating GL context" << std::endl;

_glContextModule->createContext();

std::cout << "Creating new map" << std::endl;

GlobalMapModule().createNewMap();

std::cout << "RadiantTest::Setup done" << std::endl;
}

/// Override this to perform custom actions before the main module shuts down
Expand Down Expand Up @@ -168,12 +144,6 @@ class RadiantTest :
auto fullPath = _context.getCacheDataPath() + "test.log";
_testLogFile.reset(new TestLogFile(fullPath));
_coreModule->get()->getLogWriter().attach(_testLogFile.get());

//if (strenv("DR_VERBOSE_TEST_LOG") != "")
{
_consoleLogger.reset(new ConsoleLogger);
_coreModule->get()->getLogWriter().attach(_consoleLogger.get());
}
}

virtual void setupGameFolder()
Expand Down

0 comments on commit f4d2416

Please sign in to comment.