This site is no longer active and is available for archival purposes only. Registration and login is disabled.

what is the best way to trap 'NEW' failling to allocate memo


what is the best way to trap 'NEW' failling to allocate memo

Postby Conan » Nov 29, 2005 @ 9:11pm

What is Best in Life ?
User avatar
Conan
pm Member
 
Posts: 1309
Joined: Dec 24, 2001 @ 5:16am
Location: the Shades, Ankh-Morpock


Postby Kzinti » Nov 29, 2005 @ 9:39pm

Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby Conan » Nov 30, 2005 @ 7:24am

if NEW was returning a NULL I could trap it easily however VS2005 seems to do something else. I am getting code stepping over my test for NULL and an invalid pointer. In addition I don't know if Hekkus uses NEW or not but it is now not failing when it fails to load a WAV resource. The pointer to the data is invalid but Hekkus thinks it is and plays it causing a crash. I should point out that it's not Hekkus or my code which remain unchanged but instead it's the compiler & linker which I think have changed in some way I'm not yet understanding. All my game works except WAVs.
What is Best in Life ?
User avatar
Conan
pm Member
 
Posts: 1309
Joined: Dec 24, 2001 @ 5:16am
Location: the Shades, Ankh-Morpock


Postby Digby » Nov 30, 2005 @ 9:11pm

You might want to move this to the Developer's forum.

So if I understand you correctly, you claim that operator new returns a non-NULL address, but then when this memory is supposedly accessed by a 3rd Party library it crashes?

Have you tried to access the memory yourself immediatly after the the allocation to see if the problem still exists?

If you're using new to allocate a buffer, have you ensured that the buffer is the correct size? If it's too small, the returned address would be valid, but the library may think that it's larger and caused an overrun.

Have you looked at the crash in the debugger to determine if it's due to reading/writing to this buffer that you've allocated?

Can you post the line of code that makes the call to new, along with the assembly code generated by the compiler for the call?
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Postby Conan » Nov 30, 2005 @ 9:20pm

How did this get in the general forum??? Will see if I can move.
I can't post the code that fails cause there's no debug version of Hekkus. All I know is that I can force the error or make it go away by changing where it does the loading. As this code HAS NOT CHANGED since eVC3 it's a setup issue or linker or memory management change or whatever but very hard to do much until I know I can trap the errors happening.

As I can't debug Hekkus I am moving the problem into my code by loading Hekkus WAVs earlier. I can then see that NEW does not act correctly. I will have time on Friday to do a sample to show what happens I hope.

No option to move to another forum, Do I need a moderator to do this??? :wink:
What is Best in Life ?
User avatar
Conan
pm Member
 
Posts: 1309
Joined: Dec 24, 2001 @ 5:16am
Location: the Shades, Ankh-Morpock


Postby sponge » Dec 1, 2005 @ 4:25am

holy internets batman.
User avatar
sponge
Not sponge
 
Posts: 12779
Joined: Jan 13, 2002 @ 8:04am
Location: New Hampshire


Postby BIGBEN » Dec 6, 2005 @ 11:30am

User avatar
BIGBEN
pm Member
 
Posts: 281
Joined: Mar 18, 2003 @ 10:18pm
Location: Saint-Petersburg, Russia


Postby drgoldie » Dec 6, 2005 @ 1:47pm

drgoldie
pm Member
 
Posts: 330
Joined: Jan 10, 2003 @ 10:46am
Location: Vienna


Postby BIGBEN » Dec 6, 2005 @ 2:13pm

Or maybe look at STLPort's allocate() to make it faster.
User avatar
BIGBEN
pm Member
 
Posts: 281
Joined: Mar 18, 2003 @ 10:18pm
Location: Saint-Petersburg, Russia


Postby Kzinti » Dec 6, 2005 @ 5:51pm

Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby Digby » Dec 6, 2005 @ 6:54pm

Kzinti is correct. From :

If there is insufficient memory for the allocation request, by default operator new returns NULL. You can change this default behavior by writing a custom exception-handling routine and calling the _set_new_handler run-time library function with your function name as its argument. For more details on this recovery scheme, see The operator new Function.

I'm pretty certain that C++ EH is now supported on WM devices and has been for a while. More info . I never use the stuff though.
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Postby InexorableTash » Dec 7, 2005 @ 6:00am

Note that older Microsoft C++ compilers used a "non-throwing new" which returned NULL. Newer ones default to a "throwing new", but you can change this with a compiler flag.

This sounds like it could be the source of the problem; code written for devices compiled with eVC++ 3/4 would probably have returned NULL. In VS2005 the compiler front end is the same between desktop and devices, so it may be a throwing new by default.

This has a partial explanation:
User avatar
InexorableTash
pm Member
 
Posts: 99
Joined: Sep 13, 2002 @ 6:14am


Postby Conan » Dec 7, 2005 @ 10:20am

Many thanks guys, I have a day's leave on Friday to play with this. The Hekkus code was compiled with eVC3 I think so I have no control of that but I can set up the exception handler for my NEW requirements.

The thing I still don't understand here is that the WAV files Hekkus loads are there and working from the main loop but not working in the actual functions that call them so I have 2 issues not just the NEW thing.
What is Best in Life ?
User avatar
Conan
pm Member
 
Posts: 1309
Joined: Dec 24, 2001 @ 5:16am
Location: the Shades, Ankh-Morpock


Postby BIGBEN » Dec 7, 2005 @ 12:16pm

As I remeber Hekkus license, if you provided donation you can get the source code. Anyway I'm sure Thomas Maniero would be glad to give you the source code of Hekkus to make things work with VS2005.

http://www.shlzero.com/modules.php?name ... page&pid=2

Hope it helps,

P.S. Thank you for pioneering through VS2005 ;)
User avatar
BIGBEN
pm Member
 
Posts: 281
Joined: Mar 18, 2003 @ 10:18pm
Location: Saint-Petersburg, Russia


Postby Conan » Dec 7, 2005 @ 5:29pm

What is Best in Life ?
User avatar
Conan
pm Member
 
Posts: 1309
Joined: Dec 24, 2001 @ 5:16am
Location: the Shades, Ankh-Morpock


Next

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron