2017-09-30 11 views
0

Je crée une application Java en utilisant la stratégie de buffer. Le seul problème est quand j'utilise la stratégie tampon maximisé sur mes graphiques intégrés, il se bloque avec cette erreur:Stratégie de tampon Java Affichage multi-pilotes

Exception in thread "Thread-2" java.lang.IllegalStateException: Buffers have not been created

Je crois que la raison pour le faire tomber moi à l'aide d'une vidéo-carte AMD et les graphiques intégrés sur un ensemble multi-moniteur, ou en d'autres termes, deux moniteurs utilisent les graphiques de la carte vidéo AMD et un moniteur utilise les graphiques intégrés.

En résultat, je ne peux pas maximiser mon application sur le moniteur igpu ran, mais peut maximiser ma fenêtre sur les moniteurs exploités par la carte vidéo.

Avez-vous une explication sur pourquoi Java me donne de la merde? Aussi, y a-t-il une solution pour que je puisse aussi maximiser ma fenêtre sur mon moniteur igpu ran?

Voici comment les tampons sont créés et utilisés:

Note de côté, chaque fois que l'objet graphique est utilisé, j'utilise g.drawImage(BufferedImage, x, y, null);

private void render() { 
    BufferStrategy bs = this.getBufferStrategy(); 
    if(bs == null) { 
     this.createBufferStrategy(3); //creation 
             //this being a class that implements Runnable 
     return; 
    } 

    Graphics g = bs.getDrawGraphics(); //bufferstrategy is converted to graphics here 

    g.setColor(Color.black); 
    g.fillRect(0, 0, mutableWidth, mutableHeight); 

    handler.render(g); //Graphics is transported to hundreds of objects to get displayed 

    g.dispose(); 
    bs.show(); 
} 

Je crois que vous n'avez pas besoin de lire la classe entière qui implémente runnable, mais juste au cas où vous faites:

package GenRuntime; 

import GenRuntime.GameObjects.Block.Block; 
import GenRuntime.Handler.Handler; 
import UI.UIInput.KeyInput; 
import Resources.Initializer; 

import java.awt.*; 
import java.awt.image.BufferStrategy; 

public class Game extends Canvas implements Runnable { 

    private static final long serialVersionUID = -240840600533728354L; 

    public static final int WIDTH = 800, HEIGHT = WIDTH /12 * 9; 

    private int mutableWidth, mutableHeight; 
    private int windowXLoc, windowYLoc; 

    private Thread thread; 
    private boolean running = false; 

    private Handler handler; 

    Window window; 

    public Game() { 
     handler = new Handler(); 
     this.addKeyListener((new KeyInput(handler))); 

     window = new Window(WIDTH, HEIGHT, "Survior", this); 
     mutableHeight = HEIGHT; 
     mutableWidth = WIDTH; 
    } 

    public synchronized void start() { 
     thread = new Thread(this); 
     thread.start(); 
     running = true; 
    } 

    public synchronized void stop() { 
     try { 
      thread.join(); 
      running = false; 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    public int Frames; 

    public void run() { 
     long lastTime = System.nanoTime(); 
     double amountOfTicks = 60.0; 
     double ns = 1000000000/amountOfTicks; 
     double delta = 0; 
     long timer = System.currentTimeMillis(); 
     int frames = 0; 
     while (running) { 
      long now = System.nanoTime(); 
      delta += (now-lastTime)/ns; 
      lastTime = now; 
      while (delta >= 1) { 
       tick(); 
       delta--; 
      } 

      if (running) 
       render(); 
      frames++; 

      if(System.currentTimeMillis() - timer > 1000) { 
       timer += 1000; 
       Frames = frames; 
       System.out.println("FPS: " + frames); 
       frames = 0; 
      } 
     } 
    } 

    private void tick() { 
     handler.tick(); 
    } 

    private void render() { 
     BufferStrategy bs = this.getBufferStrategy(); 
     if(bs == null) { 
      this.createBufferStrategy(3); 
      return; 
     } 

     Graphics g = bs.getDrawGraphics(); 

     g.setColor(Color.black); 
     g.fillRect(0, 0, mutableWidth, mutableHeight); 

     handler.render(g); 

     g.dispose(); 
     bs.show(); 
    } 

    public static void main(String[] args) { 
     Initializer.init(); 

     Block b = new Block(); 
     new Game(); 
    } 

    //The rest of the code is getter and setter methods. Don't worry about them 

    public void setSize(int width, int height) { 
     mutableHeight = height; 
     mutableWidth = width; 
    } 

    public void setSize(Dimension dim) { 
     mutableWidth = dim.width; 
     mutableHeight = dim.height; 
    } 

    public void setWindowLoc(int x, int y) { 
     windowXLoc = x; 
     windowYLoc = y; 
    } 

    public void setWindowLoc(Point p) { 
     windowXLoc = p.x; 
     windowYLoc = p.y; 
    } 
    public int getMutableWidth() { 
     return mutableWidth; 
    } 

    public int getMutableHeight() { 
     return mutableHeight; 
    } 

    public int getWindowXLoc() { 
     return windowXLoc; 
    } 

    public int getWindowYLoc() { 
     return windowYLoc; 
    } 
} 
+0

Vous devrez montrer le code à la façon dont les tampons sont créés/manipulés/utilisés. –

+0

@PaulT. Il a été mis à jour –

+0

Rien ne semble hors de propos pour moi, mais le même message d'erreur a été demandé dans le passé. Peut-être l'un de ces [ici] (https://stackoverflow.com/questions/3435994/buffers-have-not-been-created-whilst-creating-buffers), ou [ici] (https://stackoverflow.com/ questions/6436944/java-illegalstateexception-buffers-have-not-been-created) peut vous aider? –

Répondre