Issue 243: Gc.run(true) possibly destroying values still in use
Status:  New
Owner: ----
Reported by m22spen...@gmail.com, May 28, 2013
What steps will reproduce the problem?
1. I have no minimal case to reproduce (yet)

What is the expected output? What do you see instead?
Program is expected to complete, but crashes instead. (Same app works under neko without failure)

What version of the product are you using? On what operating system?
haxe (r6707), hxcpp 3.0.2,  Windows 7 Professional x64

Please provide any additional information below.

The code crashing .mapi's String->Bytes (simple image loader). running a Gc.run(true) afterwards will cause crashes with the following stack trace:

 	ntdll.dll!_NtRaiseException@12()	Unknown
 	ntdll.dll!_KiUserExceptionDispatcher@8()	Unknown
 	Pixwir.exe!memcpy(unsigned char * dst, unsigned char * src, unsigned long count) Line 305	Unknown
>	Pixwir.exe!String::String(const Dynamic & inRHS) Line 277	C++
 	Pixwir.exe!Lambda_obj::mapi(Dynamic it, Dynamic f) Line 91	C++
 	Pixwir.exe!`encoder::EncoderCore_obj::processState'::`31'::_Function_1_6::run(int n, hx::ObjectPtr<List_obj> b) Line 513	C++
 	Pixwir.exe!`encoder::EncoderCore_obj::processState'::`31'::_Function_1_6::__run(const Dynamic & inArg0, const Dynamic & inArg1) Line 521	C++
 	Pixwir.exe!Lambda_obj::mapi(Dynamic it, Dynamic f) Line 91	C++
 	Pixwir.exe!encoder::EncoderCore_obj::processState(Dynamic state, String asset_name, String output_dir, Dynamic config) Line 526	C++
 	Pixwir.exe!encoder::EncoderCore_obj::process(hx::ObjectPtr<Input_obj> input, String output_dir) Line 149	C++
 	Pixwir.exe!ArgRunner_obj::__construct() Line 340	C++
 	Pixwir.exe!ArgRunner_obj::__new() Line 362	C++
 	Pixwir.exe!Pixwir_obj::__new() Line 26	C++
 	Pixwir.exe!Pixwir_obj::main() Line 40	C++
 	Pixwir.exe!main(int argc, char * * argv) Line 12	C++
 	Pixwir.exe!__tmainCRTStartup() Line 240	C
 	kernel32.dll!770633aa()	Unknown
 	[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]	
 	ntdll.dll!___RtlUserThreadStart@8()	Unknown
 	ntdll.dll!__RtlUserThreadStart@8()	Unknown

May 28, 2013
Project Member #1 gameh...@gmail.com
Hi
Does this involve a ObjectMap<> ?  I have a known issue with GC on the keys, and the fix missed the haxe 3.0 cutoff by one day - we are looking to do a hotfix.
I have attached a file you can replace in cpp/_std/haxe/ds/ObjectMap.hx and see if that fixes things.  Otherwise, a snippet of source code may help me reproduce the problem.
ObjectMap.hx
2.4 KB   View   Download
May 28, 2013
#2 m22spen...@gmail.com
Not using ObjectMap. This same error occurs in 2.10. Something I forgot to include in the first post, The (*this) within String::String constructor is null.

I'm sorry for not having a small code snippet. I'll try to get something tomorrow.

I doubt it will help much, but here is the code that seems to be related to the crash.

var buckets = buckets.mapi(function(n,b) {
				return b.mapi(function(i,frame) {
                        status('Loading ${ct++}/$totalFrames');
                        var image = frame.framePath.imageDataOfPath();
                        image.__data = [{x:sep_with32_offset, y:0, frame:frame.frameNumber}];

                        var cols = Std.int(w / cw + .99)+1;
                        var rows = Std.int(h / ch + .99);

                        var squares = iter.map(function(c) {
                                var k = image.cropFixed(c.x*cw-sep_with32_offset, c.y*ch, cw, ch);
                                if (k.crc == emptycrc) {
                                    return null;
                                }
                                var i  = new tools.Image(c.x*cw-sep_with32_offset, c.y*ch, k);
                                i.frame = frame.frameNumber;
                                return i;
                            })
                        .Where(function(s) return s!=null);
                        return squares;
                    })
                .SelectMany(function(m) return m)
                .array();
				status('$logname: Bucket complete $n/$nb');
			});
		
		Gc.run(true);


Aug 22, 2013
Project Member #3 gameh...@gmail.com
Hi,
Are you still having problems with this code?  Is it possibly a buffer overrun in one of the image routines?  If you have a small example - or pm me a bigger project at my gmail account - then I can have a proper look.