Having trouble with emulator

enonod

Well-Known Member
Licensed User
Longtime User
The emulator works OK and while debugging it is OK. I have obviously misunderstood its use.
If I upload the program with debug information and attach the debugger it hangs awaiting connection if I don't have any Breakpoint. (I have noticed that if there is one I can add another while debugging).

If I detach the debugger and information in order to simply run the program it hangs again.
Is it the case that the emulator is only for debugging?
Where have I gone wrong please?
 

klaus

Expert
Licensed User
Longtime User
If I detach the debugger and information in order to simply run the program it hangs again.
What exactly do you mean with this ? I don't understand the problem you have.

- If you have 'Include Debug Information' and 'Attach Debugger' checked then the Emulator or the device shows a toastmessage 'Waiting for IDE debugger to connect'.
- If you have 'Include Debug Information' and 'Attach Debugger' unchecked then the Emulator or the device doesn't shows the message and is not waiting.
After having unchecked the two options you need to compile the program once again.
The Emulator is not only for debugging. When a program is compiled you find it in the program screen and you can run it on it's own.

If you compile for a device or distribution you must uncheck the two options.

Best regards.
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Thank you klaus. I hadn't realised that without debugging the compiled program appeared in the Program screen. That has solved that problem.

1. If I have 'Include Debug Information' and 'Attach Debugger' checked and compile the program without any breakpoint the waiting message stays there and even if I then click a breakpoint it will not continue.

2. However if I do have a breakpoint before I compile it works and I can add another breakpoint while emulating.
So why can I not do 1. above and add a breakpoint after I start?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If I have 'Include Debug Information' and 'Attach Debugger' checked and compile the program without any breakpoint the waiting message stays there and even if I then click a breakpoint it will not continue.
It shouldn't behave like that. Note that Include debug information option is not relevant when Attach debugger is checked (it will be removed for the next version).
Have you checked the unfiltered logs for any related error message?
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
I have now that you suggested it. I get a continuous stream of...

GC_FOR_MALLOC freed 21806 objects / 524280 bytes in 58ms

The numbers keep changing and also repeat many times and not in the same sequence at about 3 per second.

If I 'pause' the program shows that it was running by stopping at some 'seemingly' random place and the messages slow down to about one per second.

If I 'continue' then the speed is about 2 per second.

The program image does appear on screen but it seems only after I 'pause' otherwise the waiting message sits there and the progress circle is stationary.

The Windows 7 dialog says completed successfully.
I have just noticed that after about 5 minutes the program has 'arrived' and the messages stop with...
**Avtivity (main) Resume**
Displayed activity .../...main: 261078 (total 261078 ms)
request time failed. java.net.SocketException: Address family not supported by protocol

There we are, maybe I have done something wrong.
[EDIT] I note that before all these memory allocation numbers I get about 40/50 lines of text but cannot find a way to copy it.
Some of it says Force stopping package
Scanning package
Shutting down VM
The screen of messages eventually clears and the original messages I mentioned above continue (that is why I never noticed the 40/50 lines), then eventually the program 'arrives'

[EDIT-2] I note that when the program 'eventually' arrives I cannot stop it with a breakpoint. If I enter a breakpoint while the waiting message is present then it is accepted and pauses the program even though it has not been displayed at that time.
 
Last edited:
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
It is not in a suitable state at present to be posted, but the problem 'seems' not to be the program (full of patches and temps) because it works perfectly stepping while debugging. When no breakpoints are entered and I send the program for debugging it takes for ever to display the first image and then sits there.
If I enter a breakpoint it is quick and does as expected, so really I guess my question has been filtered down to, am I using the debugger incorrectly by even attempting to send a program without an initial breakpoint compiled in?
Secondly am I wrong in assuming that when it finally appears (without a breakpoint) why does it appear stopped?
If I should not be doing this, why am I permitted to?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
When developping I always use the debugger, most of the time even without breakpoints nor Logs.
I have never encountered a program stopping without a breakpoint, I only get the 'Waiting..' message and the program runs. Depending on what the program does, loading a big database or accessing the web can take a little time but doesn't stop the program.
So i suspect that there is something in your program and that's the only reason why I asked for your project to test if this happes here also.

Best regards.
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
That information is useful because, yes I get the waiting message but for a long time and presumably the program is running because pause stops it, but nothing is visible except the message.
Then eventually, especially if I pause, the message goes and I get the image.

I will have to tidy up the temps etc. and make it presentable to upload.
I need to do a few more tests.
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
[EDIT to last post]I have realised from your comment last post, that in fact it must be working OK, what I didn't realise was that I need to press pause then continue, in sequence continually and then the program works OK. I expected that if I press continue that the program would then run (slowly perhaps) and be visibly running by showing the changes on screen. It doesn't it shows no screen changes until I pause/continue then it does.
So if that is how it should work then, thank you klaus.

[Edit]It would be handy if it could pause/continue ie step on its own at varying speed.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
I still don't really understand what you are doing when debugging.
When I run a program without a breakpoint it runs normaly without stopping and without pressing any of the buttons in the lower left corner of the IDE.
When I have breakpoints, I use the second button from the left to step line by line through the program and or the left most button to go to the next breakpoint or to continue and hoover over the variables in the code to see their content.
I have never used the pause button.

Best regards.
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
I am therefore still confused.
I normally do exactly as you say and step through code between breakpoints etc.
However I happened to send the program without a breakpoint and noticed it took forever to get rid of the waiting to connect message.
I also noticed that if I pressed pause the program indicated that it was running because it did pause and stopped on some apparently random line.
Until then there was no indication of the program being present.
Having paused it, some short while later the program image appeared.
I then alternated between pause/continue continuously and the program acted as if there were a breakpoint and I was pressing F5.
Everything seemed normal except there was no breakpoint!
The program will not move unless I press continue/pause.
I cannot imagine anything in the program causing such behaviour and you comment made me feel that this is how it should act if I didn't have a breakpoint, i.e. it provided one, but it took me a while to ascertain this.

Obviously wrong and as you say it should run continuously without a breakpoint, which is what I originally expected.

While the debugger is waiting to connect during this no breakpoint period, I get the Malloc messages as shown earlier and the progress circle does not move until I press pause.
 
Last edited:
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
In addition I have noticed that the emulator keeps my cat warm!
She sleeps on my table next to the computer case.
When I run the emulator the computer fan always starts and continues until I stop the emulator.
When I send the program without a breakpoint, after several minutes the fan stops!!!
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
I attach my in progress file, now tidied up; if it could be run on the emulator without a breakpoint on line 71 and then with.
Press Start to run, the other button is not yet complete.
Any comments regarding the result would be appreciated.

You can of course remove logging of variables

ANY comments about my technique of attempting to program using B4A that are downright wrong, or there is a better way, please tell me, this is a learning exercise.
 

Attachments

  • Life-1.zip
    7.8 KB · Views: 178
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problem comes from your program, as I suspected.
You are drawing 500 times a grid of 45 * 45 rectangles, this takes time.
As you are doing it at the program start, the screen is not updated before the whole process is finished and the 'Waiting...' messages remains until the end.
I modified a bit your program to show this.
- replaced 500 times to 20 timesj, to limit the time.
- added a display in the Activity title showing the For loop count.
- added a DoEvents in the For loop to update the screen.

Best regards.
 

Attachments

  • Life-1_1.zip
    7.9 KB · Views: 161
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
I have not had time to inspect everything and thank you for your assistance.
The loop of 500 was simply to ensure the program operated more than once while testing.
In fact the loop should not operate before anything, it is supposed to run a complete cycle of the program and then start again. One cycle should be one generation and because a generation is likely to be slow it should have been visible.
I find it difficult to explain, but I would have expected one generation to last say one second, thus 500 seconds would be enough for me to check it is working.
It should run for ever really but I don't know how to do that or know where it should go when dealing with Android.
I don't understand why you say at the programs start... the program is supposed to be IN the loop NOT after it. Can you explain what I should have done?
Everything that happens is within Draw.
[EDIT]Also I thought the invalidate updated the screen I didn't know I had to doEvents. It is that item that made it work! Thanks but can you explain what I have obviously failed to find out... why DoEvents?
 
Last edited:
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
klaus, it is clearer now that I have studied your change. It was the DoEvents that solved it. I put it back to 500 and it still works but lasts longer, so I was updating what should go on screen but presumably??? not telling it to put it there.
I thought DoEvents was simply something to allow other events like keyboard to not be blocked by the program running.
Anything you can add to my misunderstanding will be welcome.
[EDIT]Got it ! Thank you very much for the answer klaus. Also I have changed the loop for a Timer which is how I began but when it didn't work I assumed it was the time. Now it works fine. Immensely grateful.
 
Last edited:
Upvote 0
Top