Sign in to follow this  
GlennLatomme

Bubblegum Engine error

Recommended Posts

GlennLatomme    100
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: [url="http://www.gamedev.net/topic/617343-bubblegum-engine-error/page__gopid__4896480#entry4896480"]click here[/url]

[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

[code]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[/code]
[/spoiler]

Greetings Glenn.

Share this post


Link to post
Share on other sites
GlennLatomme    100
[quote name='SiCrane' timestamp='1324513006' post='4896353']
It would probably help if you mentioned what error you are getting.
[/quote]

^^ Forgot that one xD
added tot the main question, thanks for telling me.

Share this post


Link to post
Share on other sites
SiCrane    11839
The linker can't find definitions for your AGame constructor and destructor. It looks like you didn't give them function bodies.

Share this post


Link to post
Share on other sites
GlennLatomme    100
Already back :D

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

Full code:
[spoiler][subheading]MainEngine.cpp[/subheading][code]// ===================================================
// | 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);
}[/code]
[subheading]MainEngine.h[/subheading]
[code]
// ===================================================
// | 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;
};
[/code]
[/spoiler]
All other code can be found in[url="http://www.gamedev.net/topic/617343-bubblegum-engine-error/page__view__findpost__p__4896345"] first topic[/url]

Share this post


Link to post
Share on other sites
L. Spiro    25620
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

Share this post


Link to post
Share on other sites
GlennLatomme    100
[quote name='YogurtEmperor' timestamp='1324554105' post='4896484']
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
[/quote]
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

Share this post


Link to post
Share on other sites
GlennLatomme    100
[quote name='YogurtEmperor' timestamp='1324555265' post='4896490']
The point is, what value is being given to SetGame()?


L. Spiro
[/quote]
[code] MainEngine engine;
AGame *gamePtr = new FirstGame();

engine.SetGame(gamePtr);
if (SUCCEEDED(engine.Initialize()))
{
engine.ProgramLoop();
}
delete gamePtr;[/code]

Share this post


Link to post
Share on other sites
turbello    115
Something is not going to work.

Your Initialize() method is returning an integer. 'SUCCEEDED' don't check that.
You can do this:
[code]if( engine.Initialize() ) // this automatically gives a 0 == true
{
engine.ProgramLoop();
}[/code]
Or you can do this:
[code]HRESULT Initialize()
{
HRESULT hr;

// Initialize the engine

return hr;
} [/code]

Share this post


Link to post
Share on other sites
GlennLatomme    100
[quote name='turbello' timestamp='1324556167' post='4896494']
Something is not going to work.

Your Initialize() method is returning an integer. 'SUCCEEDED' don't check that.
You can do this:
[code]if( engine.Initialize() ) // this automatically gives a 0 == true
{
engine.ProgramLoop();
}[/code]
Or you can do this:
[code]HRESULT Initialize()
{
HRESULT hr;

// Initialize the engine

return hr;
} [/code]
[/quote]
Got some questions with that.
as you could see i did try { } catch { }
so if it wasn't succesfull it would go to quitwithError(), witch will exit the programm, so if it returns a value it must be a succsessfull creation.

and I tried adding the HRESULT, but it say's that is wasn't initialized
But i wouldn't know what value to put in the hr.

Share this post


Link to post
Share on other sites
turbello    115
If you use try - catch and exit when it fails, you don't need to return anything. You don't need to check if the initialization was succeeded because if it wasn't you would already have exited the application.

If you want to keep that try - catch, don't return anything because the return is useless.


If you want to use the HRESULT, here is an example of using it:

[code]HRESULT hr;
hr = RegisterClass( &wndClass ); // this should work :P
return hr;[/code]
The value that will be put into hr depends: [url="http://msdn.microsoft.com/en-us/library/cc704587%28v=prot.10%29.aspx"]HRESULT values[/url]

Share this post


Link to post
Share on other sites
GlennLatomme    100
[quote name='turbello' timestamp='1324558042' post='4896501']
If you use try - catch and exit when it fails, you don't need to return anything. You don't need to check if the initialization was succeeded because if it wasn't you would already have exited the application.

If you want to keep that try - catch, don't return anything because the return is useless.


If you want to use the HRESULT, here is an example of using it:

[code]HRESULT hr;
hr = RegisterClass( &wndClass ); // this should work :P
return hr;[/code]
The value that will be put into hr depends: [url="http://msdn.microsoft.com/en-us/library/cc704587%28v=prot.10%29.aspx"]HRESULT values[/url]
[/quote]
Thanks,
but i still have my error: [url="http://www.gamedev.net/topic/617343-bubblegum-engine-error/page__gopid__4896480#entry4896480"]here[/url]

Share this post


Link to post
Share on other sites
Jansic    251
0xFEEEFEEE is the fill MSVC uses when something is freed. i.e. it's trying to delete something that has already been deleted.

A quick glance at the code shows the AGame pointer is deleted both outside the class (in main) and in the destructor for the MainEngine class - which is probably the issue...

Jans.

Share this post


Link to post
Share on other sites
GlennLatomme    100
[quote name='Jansic' timestamp='1324558619' post='4896506']
0xFEEEFEEE is the fill MSVC uses when something is freed. i.e. it's trying to delete something that has already been deleted.

A quick glance at the code shows the AGame pointer is deleted both outside the class (in main) and in the destructor for the MainEngine class - which is probably the issue...

Jans.
[/quote]

Hmm now you say it, the m_abstractGamePtr is just a pointer not a new object, so I didn't have to delete it, thx!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this