Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create GL program: 0 #97

Open
eliteSchwein opened this issue Apr 30, 2021 · 20 comments
Open

Cannot create GL program: 0 #97

eliteSchwein opened this issue Apr 30, 2021 · 20 comments

Comments

@eliteSchwein
Copy link

eliteSchwein commented Apr 30, 2021

Hey there i get Cannot create GL program: 0

at drawBitmap

Code:

    override fun onGLDraw(canvas: ICanvasGL?) {
        Log.d("framework", canvas.toString())
        if (canvas != null) {
            this.canvas = canvas
            Thread {
                while (mIn == null) { Log.d("null", "null")}
                try {
                    val bm = mIn!!.readMjpegFrame()
                    canvas.drawBitmap(bm, 0, 0)
                } catch (e: IOException) {
                    e.printStackTrace()
                }
            }.start()
        }
    }
@ChillingVan
Copy link
Owner

The drawBitmap cannot be called in another threat but only in the thread in onGLDraw

@eliteSchwein
Copy link
Author

Well thats a problem, i cant use the main thread for network stuff

@ChillingVan
Copy link
Owner

Well thats a problem, i cant use the main thread for network stuff

Then the bitmap should be ready from other thread before it is passed to this TextureView

@eliteSchwein
Copy link
Author

eliteSchwein commented May 1, 2021

Its based from a inputstream from a website...
But i think i got an idea, i will try that in 10h or so because i have to sleep now.

thank you for the fast Response!

@eliteSchwein
Copy link
Author

Screenshot_20210501_165637_de.eliteschw31n.moonrakerremote.jpg

Sofar so good, except it overlays everything

@ChillingVan
Copy link
Owner

What view do you use? GlSurfaceView or GlTextureView

@eliteSchwein
Copy link
Author

self made view for now

@eliteSchwein
Copy link
Author

can you provide a methode for updating the picture? because i tried Thread.sleep in a while loop and it crashes

@ChillingVan
Copy link
Owner

Maybe you need to learn something about Android UI thread or Handler. It is a little hard to explain Thread.sleep should not be called here.

@eliteSchwein
Copy link
Author

can i somehow get the GL Thread?

@eliteSchwein
Copy link
Author

okay so i get the errmor message again, but this time from the same thread

class MjpegView : GLView {
    private var thread: Thread? = null
    private var mIn: MjpegInputStream? = null
    private var bitMap: Bitmap? = null
    private var canvas: ICanvasGL? = null
    private var glThread: Thread? =null

    private fun init(context: Context) {
        isFocusable = true
    }

    fun startPlayback() {
        if (mIn != null) {
            thread = Thread {
                while (!Thread.interrupted()) {
                    bitMap = mIn?.readMjpegFrame()

                    Log.d("GLThread", glThread?.id.toString())
                    glThread?.run {
                        canvas?.drawBitmap(bitMap, 0, 0) //ERROR
                    }
                    Thread.sleep(1000)
                }
            }
            Log.d("stream", mIn.toString())
            thread?.start()
        }
    }

    fun stopPlayback() {
        thread?.interrupt()
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        init(context)
    }

    override fun onGLDraw(canvas: ICanvasGL?) {
        glThread = Thread.currentThread()

        Log.d("GLThread1", Thread.currentThread().id.toString())
        if(canvas != null) {
            this.canvas = canvas
        }
    }

    constructor(context: Context) : super(context) {
        init(context)
    }

    fun setSource(source: MjpegInputStream?) {
        mIn = source
    }

    companion object {
    }
}

@ChillingVan
Copy link
Owner

okay so i get the errmor message again, but this time from the same thread

class MjpegView : GLView {
    private var thread: Thread? = null
    private var mIn: MjpegInputStream? = null
    private var bitMap: Bitmap? = null
    private var canvas: ICanvasGL? = null
    private var glThread: Thread? =null

    private fun init(context: Context) {
        isFocusable = true
    }

    fun startPlayback() {
        if (mIn != null) {
            thread = Thread {
                while (!Thread.interrupted()) {
                    bitMap = mIn?.readMjpegFrame()

                    Log.d("GLThread", glThread?.id.toString())
                    glThread?.run {
                        canvas?.drawBitmap(bitMap, 0, 0) //ERROR
                    }
                    Thread.sleep(1000)
                }
            }
            Log.d("stream", mIn.toString())
            thread?.start()
        }
    }

    fun stopPlayback() {
        thread?.interrupt()
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        init(context)
    }

    override fun onGLDraw(canvas: ICanvasGL?) {
        glThread = Thread.currentThread()

        Log.d("GLThread1", Thread.currentThread().id.toString())
        if(canvas != null) {
            this.canvas = canvas
        }
    }

    constructor(context: Context) : super(context) {
        init(context)
    }

    fun setSource(source: MjpegInputStream?) {
        mIn = source
    }

    companion object {
    }
}

Emmm.. You can try to get your bitmap outside your MyGLView and then set the Bitmap to MyGLView. After the bitmap set, you can call MyGLView.requestRender to trigger onGLDraw. The reqeustRender is inherited from GLSurfaceView.

@eliteSchwein
Copy link
Author

Can you provide a example? Would be great

@ChillingVan
Copy link
Owner

Can you provide a example? Would be great

    val view = MjpegView()
    
    fun startPlayback() {
         Thread {
              val bitmap = readBitmap()
              view.mBitmap = bitmap
              view.requestRender()
         }
    }

And in MjpegView

class MjpegView : GLView {
    var mBitmap = null
    fun onGLDraw() {
        mBitmap?.let {
            drawBitmap(it)
        }        
    }
}

@eliteSchwein
Copy link
Author

eliteSchwein commented May 3, 2021

Thanks alot,

I will try it later

@eliteSchwein
Copy link
Author

How can i prevent it that it shows over everything?

@eliteSchwein
Copy link
Author

okay it doesnt work very well, it crashes after some Time and the latency is crazy high

@ChillingVan
Copy link
Owner

okay it doesnt work very well, it crashes after some Time and the latency is crazy high

Can you reused the first Bitmap to avoid creating Bitmap object continuously? And you can use canvasGL.invalidateContent() to notify the Bitmap updated.

@eliteSchwein
Copy link
Author

I dont know how i reuse a bitmap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants