debugging with breakpoints (i put one in the first line of main, then use F11 or F10 to step in or step over)
bool Core::Initialize()
{
m_hwnd = new HWND;
int screenWidth = 0, screenHeight = 0;
bool result;
// Initialize the windows api.
result = InitializeWindows(screenWidth, screenHeight); <<--------------------
if (!result)
{
MessageBox(*m_hwnd, L"Initialize window FAIL", L"Bienvenido", MB_OK);
return false;
}
//...... the rest of initialization
inside InitializeWindows...
bool Core::InitializeWindows(int& screenWidth, int& screenHeight)
{
WNDCLASSEX wc;
DEVMODE dmScreenSettings;
int posX, posY;
// Get an external pointer to this object.
//ApplicationHandle = this; //MODIFIQUE OJOOOO
//m_Core = this;
// Get the instance of this application.
m_hinstance = GetModuleHandle(NULL);
// Give the application a name.
m_applicationName = L"Engine";
// Setup the windows class with default settings.
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = m_hinstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hIconSm = wc.hIcon;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = m_applicationName;
wc.cbSize = sizeof(WNDCLASSEX);
// Register the window class.
RegisterClassEx(&wc);
// Determine the resolution of the clients desktop screen.
screenWidth = GetSystemMetrics(SM_CXSCREEN);
screenHeight = GetSystemMetrics(SM_CYSCREEN);
// Setup the screen settings depending on whether it is running in full screen or in windowed mode.
if(FULL_SCREEN)
{
// If full screen set the screen to maximum size of the users desktop and 32bit.
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = (unsigned long)screenWidth;
dmScreenSettings.dmPelsHeight = (unsigned long)screenHeight;
dmScreenSettings.dmBitsPerPel = 32;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
// Change the display settings to full screen.
ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
// Set the position of the window to the top left corner.
posX = posY = 0;
}
else
{
// If windowed then set it to 800x600 resolution.
screenWidth = 800;
screenHeight = 600;
// Place the window in the middle of the screen.
posX = (GetSystemMetrics(SM_CXSCREEN) - screenWidth) / 2;
posY = (GetSystemMetrics(SM_CYSCREEN) - screenHeight) / 2;
}
// Create the window with the screen settings and get the handle to it.
*m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName,
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL);
// Bring the window up on the screen and set it as main focus.
ShowWindow(*m_hwnd, SW_SHOW);
SetForegroundWindow(*m_hwnd);
SetFocus(*m_hwnd);
// Hide the mouse cursor.
ShowCursor(false);
return true;
}
The crash occurs on "CreateWindowEx", at the moment of step over this function the program stops.
-> Outside VS, with the .exe don't crash
Here is my Core.h
#pragma once
#define WIN32_LEAN_AND_MEAN
const bool FULL_SCREEN = false;
const bool VSYNC_ENABLED = true;
const float SCREEN_DEPTH = 1000.0f;
const float SCREEN_NEAR = 0.1f;
#include "Renderer.h"
#include "inputclass.h"
#include "Camera.h"
#include "ObjectsManager.h"
//
#include "MeshRenderer.h"
#include "ColorMaterial.h"
#include "ColorShader.h"
//
#include "Game.h"
class Core
{
public:
Core();
Core(const Core&);
~Core();
//bool Initialize(HINSTANCE, HWND, int, int)
bool Initialize();
//bool InitializeSingletons
void Shutdown();
void Run();
//get window handler
LRESULT CALLBACK MessageHandler(HWND, UINT, WPARAM, LPARAM);
//singletons
inline HWND* GetHwnd()
{
return m_hwnd;
}
inline Renderer* GetRenderer()
{
return m_renderer;
}
inline ObjectsManager* GetObjManager()
{
return m_Objmanager;
}
inline InputClass* GetInput()
{
return m_Input;
}
inline Camera* GetCamera()
{
return m_Camera;
}
inline Game* GetGame()
{
return m_game;
}
inline GameObject* GetGameObject()
{
return obj1;
}
private:
bool Frame();
bool InitializeWindows(int&, int&);
void ShutdownWindows();
LPCWSTR m_applicationName;
HINSTANCE m_hinstance;
HWND* m_hwnd;
//Singletons
Renderer* m_renderer;
ObjectsManager* m_Objmanager;
InputClass* m_Input;
Game* m_game;
Camera* m_Camera;
//test
GameObject* obj1;
ColorShader* cube_shader;
ColorMaterial* cube_material;
MeshRenderer* cube_meshRenderer;
};
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static Core* m_Core = new Core;