# Access Problem

This topic is 4793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am haveing trouble with this wxWidgets problem. what I want to do is when wxWidgets in Implemented, I want to to setup the Gamewindow frame and put a GLCanvas on the gamewindow. then i will start my game loop but i can not access the GLCanvas. is there any way i can access the GLWindow like this? Mainpp.cpp:
#include "PrecompiledHeaders.h"
#include "MainApp.h"
#include "GameWindow.h"
#include "GLCanvas.h"

int Default_Window_Value = -1;
int Game_State = 1;

DWORD Default_GL_Style = wxNO_BORDER;

wxString Empty_String;

IMPLEMENT_APP( MainApp );

bool MainApp::OnInit()
{

int Default_Window_Value = -1;
DWORD Default_GL_Style = wxNO_BORDER;
wxString Empty_String;

MainGameWindow *GameWindow = new MainGameWindow( _T ( "Stromgage Game Engine" ), wxPoint( 100, 100 ), wxSize( 800, 600 ) );

GLCanvas *GLWindow = new GLCanvas( GameWindow, Default_Window_Value, wxPoint( 0, 0 ), wxSize( 800, 600 ), Default_GL_Style, Empty_String );

GameWindow -> Show( true );

GLWindow -> SetCurrent();

//	StartGame();

return true;

}

/*void MainApp::StartGame()
{

while(GameState != 1)
{

glClearColor(0.0, 0.0, 0.0, 0.0);
GLWindow -> SwapBuffer();

}

}*/


mainApp.h:
#ifndef MAINAPP_H
#define MAINAPP_H

class MainApp : public wxApp
{

public:
virtual bool OnInit();
void StartGame();

private:
wxWindow GameWindow;

};

#endif



##### Share on other sites
class MainApp : public wxApp {  public:  virtual bool OnInit();  void StartGame();  ~MainApp() { delete GLWindow; }  private:  wxWindow GameWindow;  GLCanvas *GLWindow;};

Set it to the result of the 'new' in the OnInit (I assume you have a good reason for not just making this a constructor, and that it has something to do with the IMPLEMENT_APP macro and how wxWindows is set up), and (as shown) 'delete' it in the destructor. Member variables are always available to member functions.

BTW, you don't seem to be using that GameWindow member, although you have a local variable by that name in the OnInit. That looks suspicious... may be a source of bugs?