Browse Source

Fix crash on start under windows

Signed-off-by: falkTX <falktx@falktx.com>
pull/280/head
falkTX 4 years ago
parent
commit
f6c22c918c
3 changed files with 36 additions and 23 deletions
  1. +16
    -4
      dgl/src/Window.cpp
  2. +17
    -18
      dgl/src/WindowPrivateData.cpp
  3. +3
    -1
      dgl/src/WindowPrivateData.hpp

+ 16
- 4
dgl/src/Window.cpp View File

@@ -24,16 +24,25 @@ START_NAMESPACE_DGL
// Window

Window::Window(Application& app)
: pData(new PrivateData(app, this)) {}
: pData(new PrivateData(app, this))
{
pData->initPost();
}

Window::Window(Application& app, Window& parent)
: pData(new PrivateData(app, this, parent.pData)) {}
: pData(new PrivateData(app, this, parent.pData))
{
pData->initPost();
}

Window::Window(Application& app,
const uintptr_t parentWindowHandle,
const double scaleFactor,
const bool resizable)
: pData(new PrivateData(app, this, parentWindowHandle, scaleFactor, resizable)) {}
: pData(new PrivateData(app, this, parentWindowHandle, scaleFactor, resizable))
{
pData->initPost();
}

Window::Window(Application& app,
const uintptr_t parentWindowHandle,
@@ -41,7 +50,10 @@ Window::Window(Application& app,
const uint height,
const double scaleFactor,
const bool resizable)
: pData(new PrivateData(app, this, parentWindowHandle, width, height, scaleFactor, resizable)) {}
: pData(new PrivateData(app, this, parentWindowHandle, width, height, scaleFactor, resizable))
{
pData->initPost();
}

Window::~Window()
{


+ 17
- 18
dgl/src/WindowPrivateData.cpp View File

@@ -87,7 +87,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s)
#endif
modal()
{
init(DEFAULT_WIDTH, DEFAULT_HEIGHT, false);
initPre(DEFAULT_WIDTH, DEFAULT_HEIGHT, false);
}

Window::PrivateData::PrivateData(Application& a, Window* const s, PrivateData* const ppData)
@@ -109,7 +109,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, PrivateData* c
#endif
modal(ppData)
{
init(DEFAULT_WIDTH, DEFAULT_HEIGHT, false);
initPre(DEFAULT_WIDTH, DEFAULT_HEIGHT, false);

puglSetTransientFor(view, puglGetNativeWindow(ppData->view));
}
@@ -141,13 +141,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s,
puglSetParentWindow(view, parentWindowHandle);
}

init(DEFAULT_WIDTH, DEFAULT_HEIGHT, resizable);

if (isEmbed)
{
appData->oneWindowShown();
puglShow(view);
}
initPre(DEFAULT_WIDTH, DEFAULT_HEIGHT, resizable);
}

Window::PrivateData::PrivateData(Application& a, Window* const s,
@@ -178,13 +172,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s,
puglSetParentWindow(view, parentWindowHandle);
}

init(width, height, resizable);

if (isEmbed)
{
appData->oneWindowShown();
puglShow(view);
}
initPre(width, height, resizable);
}

Window::PrivateData::~PrivateData()
@@ -214,7 +202,7 @@ Window::PrivateData::~PrivateData()

// -----------------------------------------------------------------------

void Window::PrivateData::init(const uint width, const uint height, const bool resizable)
void Window::PrivateData::initPre(const uint width, const uint height, const bool resizable)
{
appData->windows.push_back(self);
appData->idleCallbacks.push_back(this);
@@ -240,10 +228,21 @@ void Window::PrivateData::init(const uint width, const uint height, const bool r
rect.width = width;
rect.height = height;
puglSetFrame(view, rect);
}

// FIXME this is bad
void Window::PrivateData::initPost()
{
// create view now, as a few methods we allow devs to use require it
puglRealize(view);

// FIXME this is bad, the enter/leave should be well scoped. try to find a better place for it..
puglBackendEnter(view);

if (isEmbed)
{
appData->oneWindowShown();
puglShow(view);
}
}

// -----------------------------------------------------------------------


+ 3
- 1
dgl/src/WindowPrivateData.hpp View File

@@ -118,7 +118,9 @@ struct Window::PrivateData : IdleCallback {
~PrivateData() override;

/** Helper initialization function called at the end of all this class constructors. */
void init(uint width, uint height, bool resizable);
void initPre(uint width, uint height, bool resizable);
/** Helper initialization function called on the Window constructor after we are done. */
void initPost();

/** Hide window and notify application of a window close event.
* Does nothing if window is embed (that is, not standalone).


Loading…
Cancel
Save