Why does my game loop give me a blank screen?

In summary, the conversation is about a user who has used a game loop to alternate between two strings in a text view every two seconds, but is experiencing a blank screen. They are seeking help to figure out what could be causing the issue. The logcat shows that the process is not being handled and suggests that the user should not keep the loop running endlessly. They are also advised to consider the UI thread and not hold the code for a long time without releasing it periodically.
  • #1
Darkmisc
204
27
TL;DR Summary
I've used a game loop to try make a textView alternate between two different strings every two seconds. I just get a blank screen.
Hi everyone

I've used a game loop to try make a textView alternate between two different strings every two seconds. When I run it, I just get a blank screen. The textView was originally set to show "Hello World!" but not even that shows.

Does anyone know what's gone wrong?

Thanks

GameLoop:
public void GameLoop() {
    double timeChange = 0;
    double time1 = System.nanoTime();
    double time2;

    while (true) {
        time2 = System.nanoTime();
        timeChange += (time2 - time1) / 1000000000;
        time1 = time2;
        textView.setText("fadsjfsdjfklsjfklsadjf");
        if (timeChange > 2) {
            textView.setText("2");
            timeChange = 0;
        }
    }
}
Logcat says:

logcat:
 E  Not going to handle 'com.xxmassdeveloper.gamelooptest'!
2023-03-01 09:45:53.278  3598-3598  SDAgentPac...teReceiver pid-3598                             E  Not going to handle 'com.xxmassdeveloper.gamelooptest'!
---------------------------- PROCESS STARTED (25862) for package com.xxmassdeveloper.gamelooptest ----------------------------
2023-03-01 09:45:55.291 25862-25862 AppCompatDelegate       com.xxmassdeveloper.gamelooptest     D  Checking for metadata for AppLocalesMetadataHolderService : Service not found
2023-03-01 09:45:55.388 25862-25862 PhoneWindow             com.xxmassdeveloper.gamelooptest     D  forceLight changed to true [] from com.android.internal.policy.PhoneWindow.updateForceLightNavigationBar:4238 com.android.internal.policy.DecorView.updateColorViews:1510 com.android.internal.policy.PhoneWindow.dispatchWindowAttributesChanged:3216 android.view.Window.setFlags:1148 com.android.internal.policy.PhoneWindow.generateLayout:2444
2023-03-01 09:45:55.390 25862-25862 MultiWindowDecorSupport com.xxmassdeveloper.gamelooptest     I  updateCaptionType >> DecorView@2059f86[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
2023-03-01 09:45:55.391 25862-25862 MultiWindowDecorSupport com.xxmassdeveloper.gamelooptest     D  setCaptionType = 0, DecorView = DecorView@2059f86[]
2023-03-01 09:45:55.626 25862-25862 er.gamelooptes          com.xxmassdeveloper.gamelooptest     W  Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2023-03-01 09:45:55.628 25862-25862 er.gamelooptes          com.xxmassdeveloper.gamelooptest     W  Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
---------------------------- PROCESS ENDED (25862) for package com.xxmassdeveloper.gamelooptest ----------------------------
2023-03-01 09:47:39.554  3598-3598  SDAgentPac...teReceiver pid-3598                             E  Not going to handle 'com.xxmassdeveloper.gamelooptest'!
2023-03-01 09:47:39.786  3598-3598  SDAgentPac...teReceiver pid-3598                             E  Not going to handle 'com.xxmassdeveloper.gamelooptest'!
---------------------------- PROCESS STARTED (26539) for package com.xxmassdeveloper.gamelooptest ----------------------------
2023-03-01 09:47:41.959 26539-26539 AppCompatDelegate       com.xxmassdeveloper.gamelooptest     D  Checking for metadata for AppLocalesMetadataHolderService : Service not found
2023-03-01 09:47:42.042 26539-26539 PhoneWindow             com.xxmassdeveloper.gamelooptest     D  forceLight changed to true [] from com.android.internal.policy.PhoneWindow.updateForceLightNavigationBar:4238 com.android.internal.policy.DecorView.updateColorViews:1510 com.android.internal.policy.PhoneWindow.dispatchWindowAttributesChanged:3216 android.view.Window.setFlags:1148 com.android.internal.policy.PhoneWindow.generateLayout:2444
2023-03-01 09:47:42.044 26539-26539 MultiWindowDecorSupport com.xxmassdeveloper.gamelooptest     I  updateCaptionType >> DecorView@2059f86[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
2023-03-01 09:47:42.044 26539-26539 MultiWindowDecorSupport com.xxmassdeveloper.gamelooptest     D  setCaptionType = 0, DecorView = DecorView@2059f86[]
2023-03-01 09:47:42.235 26539-26539 er.gamelooptes          com.xxmassdeveloper.gamelooptest     W  Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2023-03-01 09:47:42.237 26539-26539 er.gamelooptes          com.xxmassdeveloper.gamelooptest     W  Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
---------------------------- PROCESS ENDED (26539) for package com.xxmassdeveloper.gamelooptest ----------------------------
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
Darkmisc said:
Does anyone know what's gone wrong?
You can't just keep running forever - even game loops have to sleep sometimes!
 
  • Haha
  • Like
Likes berkeman and Darkmisc
  • #3
UI thread will no resource to draw if you setText endless without quit the current method which is the same thread. And UI thread is not for holding your code for long time without release periodically.
 
  • Like
Likes Darkmisc

1. Why is my game loop not displaying anything on the screen?

There could be a variety of reasons for this issue. It could be due to an error in your code, a problem with your game engine, or a compatibility issue with your device. It is important to check for any error messages or console logs that might give you more information about the problem.

2. How do I fix a blank screen in my game loop?

The first step is to identify the root cause of the issue. Check your code for any errors or bugs, and make sure your game engine is properly configured. You should also check if your device is compatible with the game and its requirements. If all else fails, try reaching out to other developers or forums for assistance.

3. Why am I only getting a blank screen when I run my game loop?

This could be due to a problem with your rendering or drawing functions. Make sure you are using the correct syntax and that your game objects are properly initialized and updated in the loop. It is also important to check if your game assets are loading correctly.

4. What should I do if my game loop is not showing any images or animations?

There are a few things you can check for in this situation. First, make sure your image files are in the correct directory and are named correctly in your code. If you are using a game engine, check if there are any specific commands or methods you need to use to load images. You should also check for any errors in your code that could be preventing the images from displaying.

5. How do I prevent my game loop from giving me a blank screen in the future?

The best way to prevent this issue is to thoroughly test your code and make sure it is error-free before running it. It is also important to regularly check for updates or changes in your game engine or device that could affect the functionality of your game loop. Additionally, following best practices for coding and debugging can help prevent blank screen issues in the future.

Similar threads

  • Programming and Computer Science
Replies
5
Views
1K
Back
Top