Migrating project from CodeBlocks to Visual Studio 2008

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
wzerek
Posts: 7
Joined: Mon Jun 03, 2013 4:32 pm

Migrating project from CodeBlocks to Visual Studio 2008

Post by wzerek »

Hello,
I hope that maybe you'll point me in right direction, because I have no idea what to do.
I had to write a specific game with couple requirements and last of them was that it should compile in Visual Studio 2005 or 2008. I normally use CodeBlocks, so I thought I will migrate my project when it's finished because it should be easy. And so I did, my game works fine in CodeBlocks and finally I installed VS 2008 and tried to migrate it. I added include patch, libraries, example project was compiling well. And so did my project, it compiles, but constantly throws me errors when debugging.
Errors occur, when I'm trying to use any of my classes created for nodes etc that I use, for example event receiver, terrain, scene nodes and so on, every "block" has it own class for easier development. For example class CTerrain looks like this:

CTerrain.h

Code: Select all

// CTerrain - class for terrain node
 
#include <irrlicht.h>
 
using namespace irr;
 
class CTerrain {
    private:
        scene::ITerrainSceneNode* m_terrain;
        scene::ITriangleSelector* m_selector;
 
    public:
        // Constructor
        CTerrain(scene::ISceneManager* smgr, video::IVideoDriver* driver);
        // Destructor
        ~CTerrain();
 
        // GetPtr - returns pointer to ITerrainSceneNode object
        scene::ITerrainSceneNode* GetPtr();
 
        // GetSelector - returns triangle selector connected with ITerrainSceneNode object
        scene::ITriangleSelector* GetSelector();
};
CTerrain.cpp

Code: Select all

#include "CConfig.h"
#include "CTerrain.h"
 
// CONSTRUCTOR
CTerrain::CTerrain(scene::ISceneManager* smgr, video::IVideoDriver* driver) {
    m_terrain = smgr->addTerrainSceneNode(
        "textures/terrain_heightmap.png",           // heightmap
        0,                                          // parent node
        -1,                                         // node id
        core::vector3df(0.f, 0.f, 0.f),             // position
        core::vector3df(0.f, 0.f, 0.f),             // rotation
        core::vector3df(                            // scale
        CConfig::CITY_X*CConfig::TILE_SCALE,
        CConfig::TILE_SCALE,
        CConfig::CITY_Y*CConfig::TILE_SCALE),
        video::SColor ( 255, 255, 255, 255 ),       // vertexColor
        5,                                          // maxLOD
        scene::ETPS_17,                             // patchSize
        4                                           // smoothFactor
        );
 
    m_terrain->setMaterialFlag(video::EMF_LIGHTING, CConfig::LIGHT);
    m_terrain->setMaterialTexture(0, driver->getTexture("textures/terrain_texture.jpg"));
    m_terrain->setMaterialType(video::EMT_DETAIL_MAP);
    m_terrain->scaleTexture(CConfig::TEXTURE_SCALE);
 
    // triangle selector
    m_selector = smgr->createTerrainTriangleSelector(m_terrain, 0);
    m_terrain->setTriangleSelector(m_selector);
}
 
// GetPtr - returns pointer to ITerrainSceneNode object
scene::ITerrainSceneNode* CTerrain::GetPtr() {
    return m_terrain;
}
 
// GetSelector - returns triangle selector connected with ITerrainSceneNode object
scene::ITriangleSelector* CTerrain::GetSelector() {
    return m_selector;
}
Terrain node is created in main() like this (obviously):

Code: Select all

CTerrain* terrain = new CTerrain(smgr, driver);
And it throws access violation exception:
"Unhandled exception at 0x6965685f in Game.exe: 0xC0000005: Access violation."

And I'm stuck, I have no idea where to try. I feel that it's something about technical issues, environment configuration of something like that and I'm not so good at this kind of stuff :l
Thanks in advance for any help.
Best regards,
wzerek
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Migrating project from CodeBlocks to Visual Studio 2008

Post by mongoose7 »

Have you thought of, err, debugging it?
wzerek
Posts: 7
Joined: Mon Jun 03, 2013 4:32 pm

Re: Migrating project from CodeBlocks to Visual Studio 2008

Post by wzerek »

Of course, it throws exceptions when it tries to call any of my classes, but debugger just points on specific line with no additional information, that's why I'm stuck :/ For example, when I try to create CTerrain instance, debugger points there:

Code: Select all

CTerrain::CTerrain(scene::ISceneManager* smgr, video::IVideoDriver* driver) {
    m_terrain = smgr->addTerrainSceneNode(
        "textures/terrain_heightmap.png",           // heightmap
        0,                                          // parent node
        -1,                                         // node id
        core::vector3df(0.f, 0.f, 0.f),             // position
        core::vector3df(0.f, 0.f, 0.f),             // rotation
        core::vector3df(                            // scale
        CConfig::CITY_X*CConfig::TILE_SCALE,
        CConfig::TILE_SCALE,
        CConfig::CITY_Y*CConfig::TILE_SCALE),
        video::SColor ( 255, 255, 255, 255 ),       // vertexColor
        5,                                          // maxLOD
        scene::ETPS_17,                             // patchSize
        4                                           // smoothFactor
        );      <------------------------------------------------------------------------------------ DEBUGGER POINTS HERE
 
    m_terrain->setMaterialFlag(video::EMF_LIGHTING, CConfig::LIGHT);
    m_terrain->setMaterialTexture(0, driver->getTexture("textures/terrain_texture.jpg"));
    m_terrain->setMaterialType(video::EMT_DETAIL_MAP);
    m_terrain->scaleTexture(CConfig::TEXTURE_SCALE);
 
    // triangle selector
    m_selector = smgr->createTerrainTriangleSelector(m_terrain, 0);
    m_terrain->setTriangleSelector(m_selector);
}
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Migrating project from CodeBlocks to Visual Studio 2008

Post by CuteAlien »

You also have a callstack and you can display the value of all variables. In this case my best guess would be that smgr is invalid.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
wzerek
Posts: 7
Joined: Mon Jun 03, 2013 4:32 pm

Re: Migrating project from CodeBlocks to Visual Studio 2008

Post by wzerek »

First of all, thank you very much for your help and interest.
CuteAlien, in smgr i have such values:
- irr::IReferenceCounted {DebugName=??? ReferenceCounter=??? }
__vfptr CXX0030: Error: expression cannot be evaluated
DebugName CXX0030: Error: expression cannot be evaluated
ReferenceCounter CXX0030: Error: expression cannot be evaluated
- __vfptr 0x637609b0 (and here i have 96... "blocks"? or something, everyone pointing to some place in memory)

But. There's other thing - I'm also using CEventReceiver class for my event receiver. And I'm calling it even before creating Irrlicht device or scene manager. And it causes the same unhandled exception, just with another memory address. Just for tests I created device without event receiver, then I got to error with CTerrain, but the error with CEventReceiver was the very first.

It's thrown here (I'm also adding beginning of my main file):

Code: Select all

#include <irrlicht.h>
#include <time.h>
#include <iostream>
#include <vector>
#include <conio.h>
 
#include "CBuilding.h"
#include "CPlayer.h"
#include "CConfig.h"
#include "CCrosshair.h"
#include "CEventReceiver.h"
#include "CLight.h"
#include "CRedBall.h"
#include "CReflect.h"
#include "CSkydome.h"
#include "CTerrain.h"
#include "CYellowBall.h"
#include "CRead.h"
 
using namespace irr;
using namespace std;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
int main() {
    // READING DATA FROM TXT FILE
    CRead* input = new CRead();
    input->m_height = 0;
    input->m_width = 0;
    
    if(input->ReadFromFile()) {
        return 1;
    }
 
    unsigned x = input->m_height;
    unsigned y = input->m_width;
 
    // INITIALIZING CONFIG FILE
    CConfig::Init(x, y);
 
    // EVENT RECEIVER
    CEventReceiver* receiver = new CEventReceiver();
 
    // DEVICE
    irr::SIrrlichtCreationParameters params;
    params.DriverType = video::EDT_OPENGL;
    params.WindowSize = core::dimension2d<u32>(1280, 720);
    params.EventReceiver = receiver;
 
    IrrlichtDevice* device = createDeviceEx(params); <-------- EXCEPTION THROWN HERE
createDeviceEx works without receiver, but the receiver itself is not null, I've checked it. I'm getting "Unhandled exception at 0x00000000 in Game.exe: 0xC0000005: Access violation."
In addition, I'm posting my CEventReceiver class:

CEventReceiver.h

Code: Select all

// CEventReceiver - class for managing mouse events
 
#include <irrlicht.h>
 
using namespace irr;
 
class CEventReceiver : public IEventReceiver {
    public:
        bool LeftButtonDown;
 
        // Constructor
        CEventReceiver();
 
        // OnEvent - catches events and sets LMB state
        bool OnEvent(const SEvent& event);
 
        // GetLMB - returns LMB state
        bool GetLMB();
 
        // SetLMB - sets LMB state
        void SetLMB(bool b);
};
CEventReceiver.cpp

Code: Select all

#include "CEventReceiver.h"
 
CEventReceiver::CEventReceiver() {
    LeftButtonDown = false;
}
 
// OnEvent - catches events and sets LMB state
bool CEventReceiver::OnEvent(const SEvent& event) {
    if (event.EventType == EET_MOUSE_INPUT_EVENT) {
        switch(event.MouseInput.Event) {
            case EMIE_LMOUSE_PRESSED_DOWN:
                this->LeftButtonDown = true;
                break;
 
            case EMIE_LMOUSE_LEFT_UP:
                this->LeftButtonDown = false;
                break;
 
            case EMIE_MOUSE_MOVED:
                return false;
                break;
 
            default:
                break;
        }
    }
 
    else if(event.EventType == EET_KEY_INPUT_EVENT) {
        return false;
    }
}
 
// GetLMB - returns LMB state
bool CEventReceiver::GetLMB() {
    return LeftButtonDown;
}
 
// SetLMB - sets LMB state
void CEventReceiver::SetLMB(bool b) {
    LeftButtonDown = b;
}
Thanks again for any response, cheers!
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Migrating project from CodeBlocks to Visual Studio 2008

Post by mongoose7 »

Maybe you are linking your VS app against your code::blocks DLL?

To baseline the problem I think you should recompile your app and Irrlicht (for debug) and then copy the Irrlicht DLL into the app's working directory.
wzerek
Posts: 7
Joined: Mon Jun 03, 2013 4:32 pm

Re: Migrating project from CodeBlocks to Visual Studio 2008

Post by wzerek »

That was it, I've already solved it :) but you're right. Thanks guys!
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

Re: Migrating project from CodeBlocks to Visual Studio 2008

Post by lumirion »

Also cmake is a convenient tool. Once you make a cmake project file cmake can generate project files for serveral different compilers making an easy transition between development environments.
Marthog
Posts: 31
Joined: Sun Oct 03, 2010 8:33 pm
Contact:

Re: Migrating project from CodeBlocks to Visual Studio 2008

Post by Marthog »

lumirion wrote:Also cmake is a convenient tool. Once you make a cmake project file cmake can generate project files for serveral different compilers making an easy transition between development environments.
This is also possible with Code::Blocks because it is just the IDE and one can build the project with any compiler.
Rust fanboy
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Migrating project from CodeBlocks to Visual Studio 2008

Post by REDDemon »

C::B can run a cmake and now comes bundled with doxygen (or I've setted up doxygen and forget to did that)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Post Reply