Bubblegum Engine error

Started by
15 comments, last by GlennLatomme 12 years, 3 months ago
Hi,

i recently started to build an engine in order to learn more how i should program a game(engine) next year when I need to make a game for school.
now I only have had lessons in basic C++ with an 2D engine from school, which I can use as reference for making this one,
and had like 2 lessons in the win32 environment the rest of the time i was just messing around with it.

now it's just a basic Direct2D engine, but the plans are there for switching to Dx when I get this one up and running.
so if there is stuff not very clear why I did it, feel free to say it that I can look in to it, and if needed

[subheading]Second Problem [SOLVED][/subheading]See: click here

[subheading]First Problem [SOLVED][/subheading][spoiler]the problem occurs when I try to build it, I don't know why this is happening, never had that error before :(
if anyone knows why, could you please tell my where my problem is, and if possible a solution (and preferably an explanation what I did wrong to learn from my mistakes)

EDIT:
woops forgot to mention the error :P

Error 1 error LNK2019: unresolved external symbol "public: __thiscall AGame::AGame(void)" (??0AGame@@QAE@XZ) referenced in function "public: __thiscall FirstGame::FirstGame(void)" (??0FirstGame@@QAE@XZ) E:\Programming\C++\Bubblegum\V0.01\MyFirstEngineGame.obj
Error 2 error LNK2019: unresolved external symbol "public: virtual __thiscall AGame::~AGame(void)" (??1AGame@@UAE@XZ) referenced in function "public: virtual __thiscall FirstGame::~FirstGame(void)" (??1FirstGame@@UAE@XZ) E:\Programming\C++\Bubblegum\V0.01\MyFirstEngineGame.obj
Error 3 error LNK1120: 2 unresolved externals E:\Programming\C++\Bubblegum\V0.01\Debug\Bubblegum.exe 1

[/spoiler]

Greetings Glenn.
[quote name='Koenig, Frederick']"We tend to forget that happiness doesn't come as a result of getting something we don't have, but rather of recognizing and appreciating what we do have"[/quote]
Advertisement
It would probably help if you mentioned what error you are getting.

It would probably help if you mentioned what error you are getting.


^^ Forgot that one xD
added tot the main question, thanks for telling me.
[quote name='Koenig, Frederick']"We tend to forget that happiness doesn't come as a result of getting something we don't have, but rather of recognizing and appreciating what we do have"[/quote]
The linker can't find definitions for your AGame constructor and destructor. It looks like you didn't give them function bodies.
Wel that was easy fixed :P
Thanks!
[quote name='Koenig, Frederick']"We tend to forget that happiness doesn't come as a result of getting something we don't have, but rather of recognizing and appreciating what we do have"[/quote]
Already back :D

having next problem when i close my window:
Unhandled exception at 0x00ce1968 in Bubblegum.exe: 0xC0000005: Access violation reading location 0xfeeefeee.
break goes to the following code:
MainEngine::~MainEngine(){
if (m_AbstractGamePtr != NULL){
delete m_AbstractGamePtr; // here goes the break to
m_AbstractGamePtr = NULL;
}
}


Full code:
[spoiler][subheading]MainEngine.cpp[/subheading]// ===================================================
// | Bubblegum Engine (WIP)
// | Auther: Glenn Latomme
// |
// | File: main.cpp
// | File description:
// | Main file for engine
// ===================================================

#include "MainEngine.h"
#include "AGame.h"


MainEngine::MainEngine():
m_AbstractGamePtr(0),
m_windowClass(),
m_Wnd()
{

}
MainEngine::~MainEngine(){
if (m_AbstractGamePtr != NULL){
delete m_AbstractGamePtr;
m_AbstractGamePtr = NULL;
}
}
void MainEngine::quitWithError(LPCTSTR error) {
HWND parentWindow = NULL;
if (m_Wnd != NULL) parentWindow = getHandle();
MessageBox(parentWindow, error, TEXT("Runtime Error!"), MB_OK | MB_ICONERROR);

UnregisterClass(m_windowClass.lpszClassName, m_windowClass.hInstance);

if (m_Wnd != NULL) { DestroyWindow(m_Wnd); m_Wnd = NULL; }

exit(EXIT_FAILURE);
}

int MainEngine::Initialize() {
LPCTSTR title = TEXT("Bubblegum Engine");
try {
m_windowClass.style = NULL;
m_windowClass.lpfnWndProc = messageHandler;
m_windowClass.cbClsExtra = 0;
m_windowClass.cbWndExtra = 0;
m_windowClass.hInstance = GetModuleHandle(NULL);
m_windowClass.hIcon = NULL;
m_windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
m_windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
m_windowClass.lpszMenuName = NULL;
m_windowClass.lpszClassName = title;

RegisterClass(&m_windowClass);
int width = 200;
int height = 200;

m_Wnd = CreateWindow(
m_windowClass.lpszClassName,
title,
WS_OVERLAPPEDWINDOW,
(GetSystemMetrics(SM_CXSCREEN)-width)/2,
(GetSystemMetrics(SM_CYSCREEN)-height)/2,
width, height,
GetDesktopWindow(),
NULL,
m_windowClass.hInstance,
NULL);

if (m_Wnd == NULL) throw(TEXT("Window Constructor: Failed to create a new m_Wnd!"));
} catch (LPCTSTR error) {
quitWithError(error);
}

ShowWindow(m_Wnd, SW_SHOWNORMAL);
UpdateWindow(m_Wnd);

return EXIT_SUCCESS;
}

void MainEngine::ProgramLoop() {
MSG msg;
ZeroMemory(&msg, sizeof(msg));

while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}


HRESULT CALLBACK MainEngine::messageHandler(HWND m_WindowPtr, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg) {
case WM_PAINT:
return 0;
case WM_DESTROY:
PostQuitMessage(EXIT_SUCCESS);
return 0;
}
return DefWindowProc(m_WindowPtr, msg, wParam, lParam);
}

[subheading]MainEngine.h[/subheading]

// ===================================================
// | Bubblegum Engine (WIP)
// | Auther: Glenn Latomme
// |
// | File: main.h
// | File description:
// | Main header file for engine
// ===================================================

#pragma once

#include <d3d9.h>

class AGame;

class MainEngine {
public:
MainEngine();
virtual ~MainEngine();

int Initialize();
void ProgramLoop();
void SetGame(AGame *gamePtr){m_AbstractGamePtr = gamePtr;}

private:

HWND getHandle() { return m_Wnd; }
void quitWithError(LPCTSTR error);
static HRESULT CALLBACK messageHandler(HWND m_Wnd, UINT msg, WPARAM wParam, LPARAM lParam);

AGame* m_AbstractGamePtr;
WNDCLASS m_windowClass;
HWND m_Wnd;
};

[/spoiler]
All other code can be found in first topic
[quote name='Koenig, Frederick']"We tend to forget that happiness doesn't come as a result of getting something we don't have, but rather of recognizing and appreciating what we do have"[/quote]
You have not initialized some variable or another, and it was initialized by the debug-mode compiler to 0xFEEEFEEE. Following your failure to initialize it, you then read from it.

If the debugger says it is m_AbstractGamePtr, then you never set m_AbstractGamePtr to NULL.
If your constructor has “m_AbstractGamePtr(0)” (which should be NULL instead of 0 for clarity) then the only logical conclusion is that:
#1: Your constructor is never called.
#2: At some point you assign 0xFEEEFEEE to m_AbstractGamePtr after it was originally assigned NULL. In a call to SetGame() no doubt.

If m_AbstractGamePtr points to memory it did not allocate, it should not be responsible for the deletion of that memory.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


You have not initialized some variable or another, and it was initialized by the debug-mode compiler to 0xFEEEFEEE. Following your failure to initialize it, you then read from it.

If the debugger says it is m_AbstractGamePtr, then you never set m_AbstractGamePtr to NULL.
If your constructor has “m_AbstractGamePtr(0)” (which should be NULL instead of 0 for clarity) then the only logical conclusion is that:
#1: Your constructor is never called.
#2: At some point you assign 0xFEEEFEEE to m_AbstractGamePtr after it was originally assigned NULL.


L. Spiro

Ok, I checked your both points, the constructor is triggerd in GameWinMain.cpp
so it should excists
and I searched my hole project for another SetGame() and none found.

and m_abstractGamePtr is still an empty class. just added some functions, but that's it
[quote name='Koenig, Frederick']"We tend to forget that happiness doesn't come as a result of getting something we don't have, but rather of recognizing and appreciating what we do have"[/quote]
The point is, what value is being given to SetGame()?


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


The point is, what value is being given to SetGame()?


L. Spiro

MainEngine engine;
AGame *gamePtr = new FirstGame();

engine.SetGame(gamePtr);
if (SUCCEEDED(engine.Initialize()))
{
engine.ProgramLoop();
}
delete gamePtr;
[quote name='Koenig, Frederick']"We tend to forget that happiness doesn't come as a result of getting something we don't have, but rather of recognizing and appreciating what we do have"[/quote]

This topic is closed to new replies.

Advertisement