Memory allocation issue with custom resource manager

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

jherico
Just popping in
Just popping in
Posts: 2
Joined: Thu Jul 24, 2014 05:39

Memory allocation issue with custom resource manager

Postby jherico » Mon Nov 24, 2014 22:44

I'm attempting to integrate CEGUI into some of my example code for the Oculus Rift. However, I already have my own resource management setup and want to allow CEGUI to use it by creating a custom ResourceProvider. But I'm running to a bit of a problem with memory allocation and deallocation. The problem is that I'm using the CEGUI dynamic library build, but the resource manager I'm creating is inside my own executable.

When I implement *void ResourceProvider::loadRawDataContainer(const CEGUI::String& filename, CEGUI::RawDataContainer& output, const CEGUI::String& resourceGroup)* I have to allocate the buffer which will be assigned to the output container. However, the memory will be deallocated inside the CEGUI DLL when the container is destroyed, which results in a crash if my application and CEGUI are built with different C runtimes.

I can get around this by building with CEGUI_CUSTOM_ALLOCATORS, which allows me to then allocate the memory via CEGUI::RawDataContainer::Allocator, but this solution is less than ideal (and also, CEGUI_CUSTOM_ALLOCATORS doesn't build out of the box on OSX/Xcode, latest version).

A quick solution would be to add a RawDataContainer::allocate(size_t s) method so that I could force the allocation to the CEGUI side of the DLL, regardless of whether I set CEGUI_CUSTOM_ALLOCATORS. In point of fact, since RawDataContainer takes responsibility for deleting the allocated memory in its release() method, I would suggest removing setData() altogether and forcing the use of the propose allocate() method so that RawDataContainer can't attempt to deallocate memory it doesn't own.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Memory allocation issue with custom resource manager

Postby Ident » Tue Nov 25, 2014 13:54

Why do you build your application with a different C runtime than you built CEGUI? This does not seem like a good idea in any case. Is there a good reason you need to do it this way?
CrazyEddie: "I don't like GUIs"


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 8 guests