Jump to content

Leadwerks and home-made classes: bit of a problem


Nevadaes
 Share

Recommended Posts

Hello all,

 

I'm having a little problem here with the Leadwerks engine. For now I've only used the Leadwerks engine in the main() function to test things and play around with it. Now, I wanted to make a simple demo with Classes and everything using Leo. So, I create a class which is supposed to be the class to hold the base of the application. It contains only an instance to the Engine class, creates the window, terminates it and run the main loop. Now, there is another class that holds other instances from other classes, such as the World class, Camera and Cube class. In the first class, a pointer to the second class is constructed and its "update" method is called, which is supposed to render the cube, the camera and update the world. But, the thing is that it doesn't work at all. Here is a more concrete example with some small code:

 

class Application
{
    public:
         Application();
         ~Application();

         void init();
         void release();
         int run();

    private:
         Engine m_Engine;
         Game* m_Game;
};

class Game
{
    public:
         Game();
         ~Game();

         void init();
         void release();
         void run();

    private:
         World m_World; 
         Cube m_Cube;
         Camera m_Camera;
};

 

*note that the two classes are in separate headers; it's only a small pseudo-code example.

 

This is only a simple example, but it shows exactly how I'm trying to do things: the Application class creates an Engine object and in the "run" function, starts the main loop. The "game" class is also instanced in the Application class, then, its "run" function is called as well in the Application's run method. Everything compiles, but when I run the thing, it just crashes. Microsoft Visual Studio C++ 2008 Express returns an unhandled exception at 0xthingy-thing in the application: Access violation reading location 0xI-don't-know.

 

My drivers are up to date, I ran several Leadwerks application before and when I put the World instance in the same class as the Engine one, it works fine. What's wrong? Why can't I separate Leadwerks components into several classes? The only thing I can do it to write a sort of interface for every functions in the engine, but that's a waste of time. There should be a way to use the engine's components in an OOP design, no? I could use the C style version of the engine and incorporate it in classes, but that would be re-writing LEO.

 

Thanks in advance for your answers.

 

EDIT:

I forgot to mention that, in our project, we are putting all of our classes in a specific DLL we're compiling relating to it's function, which means that, for example, if we have a toaster, a dinner table and an oven class, we would put it in the "kitchen" DLL to export to the main executable.

Link to comment
Share on other sites

@Rick: Even if I use LEO? LEO doesn't need to have Graphics() called, right? It just needs to have an Engine instance constructed via .Create(), right?

 

@Masterxilo: I don't have 2.3 yet, can I still ask for my account to be upgraded, or do I need to wait until I get to 2.3?

Link to comment
Share on other sites

@Rick: Even if I use LEO? LEO doesn't need to have Graphics() called, right? It just needs to have an Engine instance constructed via .Create(), right?

 

@Masterxilo: I don't have 2.3 yet, can I still ask for my account to be upgraded, or do I need to wait until I get to 2.3?

There must be a valid gl context before you can create an LE world or load anything.

So either make sure you call the LEO::Create method with the large amount of parameters or call LEO::InitGraphics in some other way (in)directly.

 

As for the forum account, you should be able to get full access no matter what version of the engine you have.

Just ask Josh(http://leadwerks.com/werkspace/index.php?/topic/127-if-you-need-access-to-the-forum/).

Link to comment
Share on other sites

Well, it seems that the application crashes after creating the World instance. I checked if the World object was a valid one via .IsValid method, which returns false. Then, when entering the main loop, the application says that the engine is suspended, when it shouldn't be.

Link to comment
Share on other sites

I'm also programming with Nevadaes, and it seems that the crash happens when trying to access an object (for example a Model or World). We have the Engine initialized in one DLL, then say I had a pointer to a World declared in the same class as the Engine, but used one of its functions directly from a different DLL, the World wouldn't exist (and yes it's been initialized - this is just an example).

 

To test this further I've created a new Engine within the class accessing the World, which works perfectly (bad practice, but it's only a test).

 

I'm almost certain that the issue is due to crossing DLL functionality, especially as the LEO classes aren't programmed to be DLL-friendly. The big question is, can we get around this without re-writing LEO for some DLL fun?

Link to comment
Share on other sites

No one said we didn't have the SDK. What we mean is that we want to have an Engine instance in class and a World instance in another class, and other engine's components, such as Cube's instances, Camera's instances, Model's instances and more stored in other classes and have it work, because the problem right now is that whenever the Engine instance and the World instance aren't in the same class, the application crashes at initialization: we don't have time to see anything, the console pops up and then crashes. It's a bit frustrating.

Link to comment
Share on other sites

Then I suggest you go to the link that masterxilo showed, and both you and Terrorist Zero send in your respective SDK registration keys for the version of LE that you have so you can get into the programming section of the forum. It makes no sense not to get yourself access if you have the SDK.

 

You will get full access to the forums on everything except the Leadwerks Editor and the LUA programming board, if you have version 2.2x and not 2.3.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...