Discussions related to Visual Prolog
kingchris
Active Member
Posts: 28
Joined: 26 Sep 2005 9:35

OnPaint race condition

Unread post by kingchris »

Code: Select all

clauses     assert_stuff1():-  % 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5         assert(mazeX( 1,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[7,3,1,1,7])),         assert(mazeX( 2,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,2,2,1,1])),         assert(mazeX( 3,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,3,1,3,1,1,3,1])),         assert(mazeX( 4,[0,0,0,6,6,0,0,0,0,0,0,0,6,6,0,0,0,0,0,0,0,6,0,0,0],[1,3,1,1,6,1,3,1])),         assert(mazeX( 5,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,3,1,5,2,1,3,1])),         assert(mazeX( 6,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,2,1,1])),         assert(mazeX( 7,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[7,1,1,1,1,1,7])),         assert(mazeX( 8,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[3,3])),         assert(mazeX( 9,[0,0,0,0,0,0,6,6,0,0,6,0,0,0,6,6,0,0,6,0,0,0,0,0,0],[1,2,3,1,1,3,1,1,2])),         assert(mazeX(10,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,3,2,1,1])),         assert(mazeX(11,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[4,1,4,2,1,2])),         assert(mazeX(12,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,4,1,3])),         assert(mazeX(13,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[2,1,1,1,2,5])),         assert(mazeX(14,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[3,2,2,6,3,1])),         assert(mazeX(15,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,9,1,1,2,1])),         assert(mazeX(16,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[2,1,2,2,3,1])),         assert(mazeX(17,[0,0,0,0,0,0,6,0,0,0,0,6,0,0,0,0,6,0,0,0,6,0,0,0,0],[3,1,1,1,1,5,1])),         assert(mazeX(18,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,2,2,5])),         assert(mazeX(19,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[7,1,2,1,1,1,3])),         assert(mazeX(20,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,2,1,2,2,1])),         assert(mazeX(21,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,3,1,4,5,1])),         assert(mazeX(22,[0,0,0,6,6,0,0,0,0,6,6,0,0,0,0,6,0,0,0,0,6,6,0,0,0],[1,3,1,3,10,2])),         assert(mazeX(23,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,3,1,1,6,6])),         assert(mazeX(24,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,2,1,1,2])),         assert(mazeX(25,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6],[7,2,1,2,5])).       assert_stuff2():-  % 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5         assert(mazeY( 1,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[7,2,1,1,7])),         assert(mazeY( 2,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,2,2,1,1])),         assert(mazeY( 3,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,3,1,3,1,3,1,3,1])),         assert(mazeY( 4,[0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0],[1,3,1,1,5,1,3,1])),         assert(mazeY( 5,[0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0],[1,3,1,1,4,1,3,1])),         assert(mazeY( 6,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,2,1,1])),         assert(mazeY( 7,[0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0],[7,1,1,1,1,1,7])),         assert(mazeY( 8,[0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,3])),         assert(mazeY( 9,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[2,1,2,1,8,2,1])),         assert(mazeY(10,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0],[2,2,1,2,1,1,1,2])),         assert(mazeY(11,[0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0],[1,7,3,2,1])),         assert(mazeY(12,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0],[1,2,3,1,1,1,1,1])),         assert(mazeY(13,[0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[4,1,1,2,6])),         assert(mazeY(14,[0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[3,3,1,1,1,3,1])),         assert(mazeY(15,[0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,2,5,2,2])),         assert(mazeY(16,[0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0],[2,2,2,1,1,1,1,2,1])),         assert(mazeY(17,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0],[1,3,3,2,1,8,1])),         assert(mazeY(18,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[6,2,1])),         assert(mazeY(19,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0],[7,1,4,1,1,3])),         assert(mazeY(20,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,4])),         assert(mazeY(21,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,6,0,0,0],[1,3,1,3,7,1])),         assert(mazeY(22,[0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0],[1,1,3,1,1,2,1,1,4])),         assert(mazeY(23,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,3,1,4,3,3])),         assert(mazeY(24,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,2,2,2,6,1])),         assert(mazeY(25,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[7,1,3,2,1,1])).   clauses     new(Parent):-         formWindow::new(Parent),         generatedInitialize(),         assert_stuff1(),         assert_stuff2().         predicates       print_loop:(::windowGDI,integer,int_list,integer) multi. clauses       print_loop(_,_Line,[],_).         print_loop(GDIObject,Line,[6|Rest],Counter):-          %GDIObject:setPen(pen(1,ps_Dash ,color_Yellow)),          GDIObject:setBrush(brush(pat_Solid,color_Yellow)),          GDIObject:drawRect(rct(base_x+(offset_x*Counter),(base_y*Line),base_x+(offset_x*Counter)+offset_x,(base_y*Line)+offset_y)),          Counter1 = Counter + 1,          print_loop(GDIObject,Line,Rest,Counter1).         print_loop(GDIObject,Line,[_First|Rest],Counter):-          %GDIObject:setPen(pen(1,ps_Solid, color_Azure)),          GDIObject:setBrush(brush(pat_Hollow,color_White)),          GDIObject:drawRect(rct(base_x+(offset_x*Counter),(base_y*Line),base_x+(offset_x*Counter)+offset_x,(base_y*Line)+offset_y)),          Counter1 = Counter + 1,          print_loop(GDIObject,Line,Rest,Counter1).   predicates     print_maze:(::windowGDI). clauses     print_maze(GDIObject):-       mazeX(Line,Cells,_Set),       print_loop(GDIObject,Line,Cells,0),       _=vpi::processEvents(),       fail.         print_maze(_GDIObject).       predicates     onPaint : drawWindow::paintResponder. clauses     onPaint(_Source, _Rectangle, GDIObject):-     Tools = GDIObject:getDrawTools(),     print_maze(GDIObject),     GDIObject:setDrawTools(Tools),     !.   % This code is maintained automatically, do not update it manually. 13:30:36-12.12.2015 facts     ok_ctl : button.   predicates     generatedInitialize : (). clauses     generatedInitialize():-         setFont(vpi::fontCreateByName("MS Sans Serif", 8)),         setText("dummyForm"),         setRect(rct(50,40,774,494)),         setDecoration(titlebar([closebutton(),maximizebutton(),minimizebutton()])),         setBorder(sizeBorder()),         setState([wsf_ClipSiblings,wsf_ClipChildren]),         menuSet(noMenu),         addShowListener(generatedOnShow),         setPaintResponder(onPaint),         ok_ctl := button::newOk(This),         ok_ctl:setText("&OK"),         ok_ctl:setPosition(216, 440),         ok_ctl:setAnchors([control::right,control::bottom]).   predicates     generatedOnShow: window::showListener. clauses     generatedOnShow(_,_):-         succeed. % end of automatic code end implement dummyForm
I am trying to solve a "crossword" type puzzle using Prolog to improve my PDC prolog usage.
This code paints the 25x25 grid with, for now, certain blocks filled with yellow. The blocks containing a 6 in the mazeX lists are to be yellow.

This code works fine. However if I do anything to force a repaint of the dialog box/form containing this code, it goes mad. CPU usage climbs such that the mouse becomes sluggish and it takes a while to bring up Task Manager and cancel this prolog program. The dialog box repaint seems to lose its background color and each little rectangle grid box is painted then lost instead of persisting. So you get a continuous marching repaint of the grid squares as though I was running on a very slow CPU.



Any ideas what I am doing wrong
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

You should not call vpi::processEvents while painting.
Regards Thomas Linder Puls
PDC
kingchris
Active Member
Posts: 28
Joined: 26 Sep 2005 9:35

Unread post by kingchris »

I only added that in later to see if it would help.

Anything else that might cause a problem

Thanks
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

I tried your code without the vpi::processEvent and I didn't have any problems with it.

(Except that you have confused the usage of base_y and offset_y in some case, causing gaps between the lines).
Regards Thomas Linder Puls
PDC
kingchris
Active Member
Posts: 28
Joined: 26 Sep 2005 9:35

Unread post by kingchris »

Thanks. I will run the program under different versions of windows to see if its related to the platform

Cheers
Post Reply