Gravity and GLife: fix crash on start.

Locking the GL context from a GLView subclass constructor can't work, as
it isn't ready yet. Move the initial setup to AttachedToWindow instead.

Fixes #8898, #10469.
This commit is contained in:
Adrien Destugues 2014-10-13 15:29:46 +02:00
parent 1883fcfcde
commit a3cdc7c588
2 changed files with 35 additions and 41 deletions

View File

@ -24,32 +24,11 @@
GLifeView::GLifeView(BRect rect, const char* name, ulong resizingMode,
ulong options, GLifeState* pglsState)
:
BGLView(rect, name, resizingMode, 0, options),
BGLView(rect, name, resizingMode, B_FRAME_EVENTS | B_WILL_DRAW, options),
m_pglsState(pglsState)
{
// Setup the grid
m_pglgGrid = new GLifeGrid(pglsState->GridWidth(), pglsState->GridHeight());
LockGL();
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
#if 0
glShadeModel(GL_SMOOTH);
#endif
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, rect.Width() / rect.Height(), 2.0, 20000.0);
glTranslatef(0.0, 0.0, -50.0);
glMatrixMode(GL_MODELVIEW);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
UnlockGL();
}
@ -68,6 +47,24 @@ GLifeView::AttachedToWindow(void)
{
LockGL();
BGLView::AttachedToWindow();
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
#if 0
glShadeModel(GL_SMOOTH);
#endif
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, Bounds().Width() / Bounds().Height(), 2.0, 20000.0);
glTranslatef(0.0, 0.0, -50.0);
glMatrixMode(GL_MODELVIEW);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
UnlockGL();
}

View File

@ -29,25 +29,6 @@ GravityView::GravityView(BRect frame, Gravity* parent)
fShade(parent->Config.ShadeID)
{
Particle::Initialize(fSize, fShade);
LockGL();
glClearDepth(1.0f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, frame.Width() / frame.Height(), 2.0f, 20000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -30.0f);
glDepthMask(GL_FALSE);
UnlockGL();
}
@ -63,6 +44,22 @@ GravityView::AttachedToWindow()
{
LockGL();
BGLView::AttachedToWindow();
glClearDepth(1.0f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, Bounds().Width() / Bounds().Height(), 2.0f, 20000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -30.0f);
glDepthMask(GL_FALSE);
UnlockGL();
}