graphics icon indicating copy to clipboard operation
graphics copied to clipboard

Graphics crash under Windows

Open vicuna opened this issue 9 years ago • 4 comments

Original bug ID: 7419 Reporter: Anax Assigned to: @dra27 Status: assigned (set by @dra27 on 2016-11-22T15:49:09Z) Resolution: open Priority: normal Severity: minor Platform: Winodws OS: Windows 10 Version: 4.02.3 Category: platform support (windows, cross-compilation, etc) Monitored by: @gasche

Bug description

In class, we did some exercices on trees, and in the fil the teacher gave us, there were a function to trace trees (the fact that it is tree is not important). I don't really know the module graphics.cma, but when I use it to trace a forest here, the forest is tarced, but when I when to close the windows with the space bar (there is the code let _ = read_key() in close_graph() at the end of the function) it crashes I have to launch again ocaml. I use Windows 10 on my computer, and a friend of mine as the same problem on his Windows. At school, we use ubuntu and it works.

Steps to reproduce

As I don't really know how really works the graphics module, I give you the caml function :

let rec trace_arbre_binaire t (xmin, xmax, ymin, ymax) h =
	match t with
	| Vide -> ()
	| Noeud_Binaire (x, t1, t2) ->
			let dy = (ymax - ymin) / h in
			let xm = (xmin + xmax) / 2 in
			let s = string_of_int x in
			moveto (xm - (10 * String.length s) / 2)  ymax;
			set_color green;
			draw_string s;
			let dx = (xmax - xmin) / 2 in
			set_color yellow;
			if t1 <> Vide then (
				moveto xm (ymax - 5);
				lineto (xmin + dx / 2) (ymax - dy + 15);
			);
			if t2 <> Vide then (
				moveto xm (ymax - 5);
				lineto (xmin + dx / 2 + dx) (ymax - dy + 15);
			);
			trace_arbre_binaire t1 (xmin, xm, ymin, ymax - dy) (h - 1);
			trace_arbre_binaire t2 (xm, xmax, ymin, ymax - dy) (h - 1)

let voir_arbre_binaire t =
	let nx = 800
	and ny = 600 in
	open_graph (" " ^ (string_of_int nx) ^ "x" ^ (string_of_int ny));
	set_color black;
	fill_rect 0 0 nx ny;
	let k = 50 in
	trace_arbre_binaire t (k,nx - k,k,ny - k) (hauteur_arbre_binaire t);
	let _ = read_key() in close_graph();;

where the type 'a arbre is

type 'a arbre_binaire =
|  Vide
|  Noeud_Binaire of 'a * 'a arbre_binaire * 'a arbre_binaire

Additional information

(I'm a French student, so I apologize for my apporxiamtive English)

File attachments

vicuna avatar Nov 21 '16 16:11 vicuna

Comment author: @dra27

64-bit OCaml?

I'm fairly sure you hitting a bug fixed in #678 (https://github.com/ocaml/ocaml/pull/678). If you're building OCaml from source, there is a version of this patch back-ported for 4.02.3 at https://github.com/metastack/ocaml-legacy/blob/master/GPR678.patch

vicuna avatar Nov 22 '16 15:11 vicuna

Comment author: @dra27

(self-assigned as a reminder to check that 4.04 doesn't exhibit this behaviour - if someone else beats me to it, feel free to close this PR)

vicuna avatar Nov 22 '16 15:11 vicuna

@dra27 if/when you have time, checking that 4.07 doesn't exhibit this behavior would be nice :-)

gasche avatar Mar 16 '19 16:03 gasche

Sure. I guess that would be 4.09 though. We are planning to make this library available for OCaml >= 4.09 only.

ghost avatar Mar 18 '19 10:03 ghost