File: check_leak_on_discontiguous_array.py

package info (click to toggle)
pyopengl 3.1.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,024 kB
  • sloc: python: 108,056; sh: 13; makefile: 8
file content (43 lines) | stat: -rw-r--r-- 1,063 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Test for github issue #47"""

import sys
import OpenGL

OpenGL.SIZE_1_ARRAY_UNPACK = False  # just for convenience
OpenGL.ERROR_ON_COPY = False  # we are checking a leak in the copying
import pygamegltest
import numpy as np
from OpenGL.GL import *
from OpenGL.GL import shaders
from sys import getrefcount


@pygamegltest.pygametest(name="Texture image 2d leak check")
def main():
    data = np.zeros([256, 256, 3], dtype='b')
    glEnable(GL_TEXTURE_2D)
    textures = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, textures[0])
    reversed_data = data[::-1]
    assert not reversed_data.flags['C_CONTIGUOUS']
    rc1 = getrefcount(reversed_data)
    for i in range(100):
        glTexImage2D(
            GL_TEXTURE_2D,
            0,
            GL_RGB,
            256,
            256,
            0,
            GL_RGB,
            GL_UNSIGNED_BYTE,
            reversed_data,
        )
    rc2 = getrefcount(reversed_data)
    assert rc1 == rc2, (rc1, rc2)
    sys.stdout.write('OK\n')
    sys.stdout.flush()


if __name__ == "__main__":
    main()