Project

General

Profile

« Previous | Next » 

Revision f8377ef8

Added by Leszek Koltunski about 7 years ago

New, cleaner way to create/destroy DistortedSurfaces.

Serious regression in StarWars (crashes!). Looks like the Node's internal FBO is being deleted and not re-created in time.

View differences:

src/main/java/org/distorted/library/DistortedSurface.java
19 19

  
20 20
package org.distorted.library;
21 21

  
22
import java.util.Iterator;
23 22
import java.util.LinkedList;
24 23

  
25 24
///////////////////////////////////////////////////////////////////////////////////////////////////
......
36 35
  static final int NOT_CREATED_YET  = -2;
37 36
  static final int DONT_CREATE      = -3;
38 37

  
39
  private static boolean mListMarked = false;
40
  private static LinkedList<DistortedSurface> mList = new LinkedList<>();
38
  private static boolean mToDo = false;
39
  private static LinkedList<DistortedSurface> mDoneList = new LinkedList<>();
40
  private static LinkedList<DistortedSurface> mToDoList = new LinkedList<>();
41 41

  
42 42
  private boolean mMarked;
43 43
  int[] mColorH = new int[1];
......
45 45

  
46 46
///////////////////////////////////////////////////////////////////////////////////////////////////
47 47

  
48
  public abstract void create();
48
  abstract void create();
49 49
  abstract void delete();
50
  abstract void destroy();
50
  abstract void recreate();
51 51

  
52 52
///////////////////////////////////////////////////////////////////////////////////////////////////
53 53
// must be called form a thread holding OpenGL Context
54 54

  
55
  static synchronized void deleteAllMarked()
55
  static synchronized void toDo()
56 56
    {
57
    if( mListMarked )
57
    if( mToDo )
58 58
      {
59
      DistortedSurface tmp;
60
      Iterator<DistortedSurface> iterator = mList.iterator();
59
      DistortedSurface surface;
61 60

  
62
      while(iterator.hasNext())
61
      int num = mToDoList.size();
62

  
63
      for(int i=0; i<num; i++)
63 64
        {
64
        tmp = iterator.next();
65
        surface = mToDoList.removeFirst();
65 66

  
66
        if( tmp.mMarked )
67
        if(surface.mMarked)
68
          {
69
          surface.delete();
70
          surface.mMarked = false;
71
          }
72
        else
67 73
          {
68
          tmp.delete();
69
          tmp.mMarked = false;
70
          iterator.remove();
74
          surface.create();
75
          mDoneList.add(surface);
71 76
          }
72 77
        }
73 78

  
74
      mListMarked = false;
79
      mToDo = false;
75 80
      }
76 81
    }
77 82

  
......
79 84

  
80 85
  static synchronized void onDestroy()
81 86
    {
82
    for( DistortedSurface surface : mList)
87
    DistortedSurface surface;
88

  
89
    int num = mDoneList.size();
90

  
91
    for(int i=0; i<num; i++)
83 92
      {
84
      surface.destroy();
85
      surface.mMarked = false;
93
      surface = mDoneList.removeFirst();
94

  
95
      if( !surface.mMarked )
96
        {
97
        surface.recreate();
98
        mToDoList.add(surface);
99
        }
86 100
      }
87 101

  
88
    mListMarked = false;
102
    mToDo = true;
103
    }
104

  
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

  
107
  synchronized void moveToToDo()
108
    {
109
    if ( mDoneList.remove(this) )
110
      {
111
      mToDoList.add(this);
112
      mToDo = true;
113
      }
89 114
    }
90 115

  
91 116
///////////////////////////////////////////////////////////////////////////////////////////////////
......
96 121
    mSizeY    = height;
97 122
    mColorH[0]= color;
98 123
    mMarked   = false;
99
    mList.add(this);
124

  
125
    if( color!=DONT_CREATE )
126
      {
127
      mToDoList.add(this);
128
      mToDo = true;
129
      }
100 130
    }
101 131

  
102 132
///////////////////////////////////////////////////////////////////////////////////////////////////
......
107 137
 */
108 138
  public void markForDeletion()
109 139
    {
110
    mListMarked = true;
111
    mMarked     = true;
140
    if( !mMarked )
141
      {
142
      mToDo   = true;
143
      mMarked = true;
144
      mDoneList.remove(this);
145
      mToDoList.add(this);
146
      }
112 147
    }
113 148

  
114 149
////////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff