Pastaspace Posted May 1, 2014 Share Posted May 1, 2014 I've been working on converting my game to 3.1's engine, and I've run into a bit of a snag. Basically, the things that handle my inventory are separate objects, in separate files from the main Start and Loop portions. These objects also contain the functions for drawing the player's inventory (a mix of DrawImage and DrawText). However, this doesn't seem to work, and I always get an "Assert failed" error. This is a basic version of what my code is doing. In my main program, I create a context window as well as an inventory object and similar. App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} inventoryObject myObject; bool App::Start() { window = Window::Create(); //Create a rendering context context = Context::Create(window); return true; } Somewhere in my InventoryObject's list of functions is the one that draws its image, it it passed the context it renders on from the main program. InventoryObject.cpp is, obviously, a separate file. void inventoryObject::DrawObject(Context* cc_Context) { cc_Context->DrawImage(myImage, 0, 0); } Then in the main loop, it calls this function. bool App::Loop() { if (window->Closed() || window->KeyDown(Key::Escape)) return false; Draw::SetColor(0,0,1); context->Clear(); Draw::SetColor(1,0,0); myObject.DrawObject(context); context->Sync(); return true; } However, again, I get an assert fail error. Is there something here that I'm missing, or do I have to draw all my context images and text in the main program only? Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 1, 2014 Share Posted May 1, 2014 Are those Start and Loop codes you posted snippets or complete code? Have you initialised the myObject in the Start method? Dont forget that you need to update and render the world. Time::Update(); world->Update(); world->Render(); //Do your drawing here context->Sync(false); Quote Link to comment Share on other sites More sharing options...
Pastaspace Posted May 1, 2014 Author Share Posted May 1, 2014 I've done all that. This is not the actual code, merely a similar example to help demonstrate what I'm trying to accomplish. What I'm trying to do is use DrawImage and similar Context functions in a separate object. I can call anything just fine in the main body where the original context object was initialized, but cannot pass it to another object for use, this is what I'm trying to figure out. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 1, 2014 Share Posted May 1, 2014 Can you post a little bit more code on initialising an where you call the drawfunctions? Passing the context (a pointer) to other classes shouldn't be a problem. I do that all the time. Quote Link to comment Share on other sites More sharing options...
Rick Posted May 1, 2014 Share Posted May 1, 2014 Are you sure it's the context giving the issue and not the image you pass to it not being created/loaded? You'd probably get the same error on the same line if that was the case. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.