We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am currently working on an assignment for my school and I am running into a problem I can not seem to solve.
As this is a graded problem I would like to ask not to give me a solution but just to point out what could be causing this or if it's a known bug.
I am coding a program that needs to draw some content. The drawing is managed by a function that is invoked at the mouseClicked event.
Before the screen is drawn, the entire screen is refreshed within the called function using background(255).
The thing I am running into is that from time to time text content is placed on top of old content or lines are drawn towards the point that make up the starting point from where the text is drawn.
It does not produce this problem every time the program runs nor are any variables used that could effect the logic behind what is happening. Most annoying is that I can not seem to reproduce it myself. Going through the application the exact same way twice could one time produce this issue and the other time everything goes fine.
Any suggestions into what could be causing this would be great.
Answers
The entire draw() function is empty and is just there because it is required if I wish to use any events. So this could not be causing any issues as far as I am aware.
I just tried changing the type of event to a mouseReleased event but this seems to trigger the same weird behavior as the mouseClicked event.
All drawing to the screen is handled from the one function I mentioned that is invoked by the mouseClick event. This function in it's turn calls a few other functions that take care of a part of the complete output that needs to be send to the screen.
Could it be that some of these smaller functions that are invoked by the function that manages what is placed on the screen run in parallel and that this messes it up?
If draw is empty rather than including background, and if sometimes your background doesn't run....
Then the most likely explanation is that you have a conditional structure that only sometimes calls background.
This would be much easier to help you diagnose if you shared an MCVE.
Hope this might help a bit. As mentioned draw() is completely empty. One of the problems seems that the rectangle in drawMenu get a with that is width / 2 and a height that is height / 2 sometimes out of the blue and other times it does not. Might also be that the origin from where the rect is drawn changes.... I have no idea. However it is not done by me in that case.
https://Processing.org/reference/redraw_.html
It is event-driven, however we are supposed to use that which is mentioned in classes during this assignment. Noloop() and reDraw() have not been mentioned.
However I tried that and placed the content of the drawScreen() function inside the draw().
Still produces the same issue.
Sorry, I dunno what is going there either. X_X
I managed to solve the problem during a hot shower (I think as it has not happened again) and thought you might wanted to know what was causing the problem.
I realized that rectMode() is changed to the center of a rectangle inside the invokeFunction() function.
If there is any type of parallel or out of order execution going on in the background, rectMode() might already be changed at times (and this could result in weird patterns when it occurs and when it doesn't).
Adding rectMode(CORNER) before drawing the rectangle solved the issue.
Might be some normal type of behavior but it caught me off guard.
Have you actually experienced the issue in the sketch you provided? It looks incomplete / broken.
If you can't verify the issue with what you are sharing then you may have already taken out the part causing the problem.
@jeremydouglass, the post above yours mentions the solution to the problem I had.
I could not provide more of the sketch as other students are working on the same assignment and it's graded. So I had to keep it a bit cryptic.
Got it.
You can also use pushStyle and popStyle to isolate your call to rectMode -- that is easier and cleaner than trying to set it back later to whatever you think it was.
println( Thread.currentThread() );
.