irrlicht way of returntypes

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

irrlicht way of returntypes

Post by Nox »

Hi,

i took a closer look to the source and wondered, why there are const references to local stored return_datas_container returned by many methods. After some time i figured out that this is due to the heap problem (there are 2 heaps. One for the lib and one for the exe).
My question:
Is not there a better way than storing the datas local in the instances and returning a reference to them? I understand that you do not want to use the dynamic runtimelibrary. But for example std::list solve this heap problem by avoiding the "simple new" operator.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I don't understand a thing here. Could you please give an example?
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

Post by Nox »

I have added some methods to CGUIFileOpenDialog and created a testcase which calls them.

Methods:
core::string<c16> getDirectoryName()
const core::list<core::stringw>& getFileNames1()
core::list<core::stringw> getFileNames2()


core::string<c16> s = getDirectoryName()
works because core::string use a own allocator

core::list<core::stringw> l = getFileNames1()
works because i give a reference to a object which remains to irrlicht

core::list<core::stringw> l = getFileNames2()
crashs because list is created inside of irrlicht, given to exe and then destroyed by the exe ->heapcrash.

"simple" way to avoid this: apply irrAllocator to core::list

EDIT: Same for core::map
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

well what's the implementation of getFileNames2? If you've implemented it yourself and it crashes then that's your fault, not irrlichts...
Image Image Image
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

JP wrote:well what's the implementation of getFileNames2? If you've implemented it yourself and it crashes then that's your fault, not irrlichts...
I guess it just returns the value, list and map don't use IrrAllocator so it crashes for the reasons Nox stated. If you remember, we had this problem with texture matrices a while back
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

Post by Nox »

It is irrlichts fault. irrList and irrMap uses delete and new directly -> used with two different heaps = crash
irrMap can not be copied so this will never happend as long as it has no copy c'tor but irrList has a copy c'tor. IrrArray and irrString are implemented quite more elegant with a irrAllocator. But just try it:

apply the patch and insert into an exe-code under windows using the dll:

Code: Select all

{
     core::list<core::stringw > test = device->foo();
}
EDIT: after that test, patch your irrlicht with https://sourceforge.net/tracker/index.p ... tid=540676 and this problem should be fixed. As allready mention irrMap does not use irrAllocator too, so the heap corruption bug may appeare there too.
Post Reply