Jump to content

libtheoraplayer hangs on destruction


TexelOne
 Share

Recommended Posts

Hi,

 

I made a function that plays an intro video (until the video ends or the user hits the escape key) using the code from Paramecij's example of libtheroaplayer (found here).

 

If I exit the loop by hitting the escape key, the TheoraManager destruction works fine and the program continues. But if the loop exits by the video reaching its end, the game hangs on the manager's destruction.

 

Shouldn't the manager's destruction work the same, no matter how the loop exits?

 

Here's the code:

//IntroVideo.CPP

#pragma comment(lib,"libtheoraplayer.lib")
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"openal32.lib")

#include "engine.h"
#include <gl/gl.h>
#include "TheoraVideoManager.h"
#include "TheoraVideoFrame.h"
#include "OpenAL_AudioInterface.h"

void showIntroVideo (short int &gState) {
  TWorld	world = CreateWorld();
  TBuffer gbuffer = CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);
  TCamera camera = CreateCamera();

  //Theora setup
  TheoraVideoManager *mgr = new TheoraVideoManager();
  OpenAL_AudioInterfaceFactory *openAIF = new OpenAL_AudioInterfaceFactory();
  mgr -> setAudioInterfaceFactory(openAIF);
  mgr -> setDefaultNumPrecachedFrames(32);
  TheoraVideoClip *clip = mgr->createVideoClip( "bunny.ogg",TH_RGB,0,1);
  clip -> setAutoRestart(false);
  float w = clip->getWidth();
  float h = clip->getHeight();
  TTexture videotexture = CreateTexture( w, h, TEXTURE_RGB );

  //video player loop:
  while (!KeyHit(KEY_ESCAPE) && !clip->isDone()) {

     //Update texture: 
     TheoraVideoFrame *f = clip->getNextFrame();
     if(f){
        BindTexture(videotexture);
        glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, w-1, h-1, 0, GL_RGB, GL_UNSIGNED_BYTE, f->getBuffer());
        clip->popFrame();
     }

     //Update:
     mgr->update(AppSpeed());
     UpdateAppTime();
     UpdateWorld(AppSpeed()) ;

     //Render:
     SetBuffer(gbuffer);
     RenderWorld();
     SetBuffer(BackBuffer());
     RenderLights(gbuffer);
     DrawImage(videotexture,0,0,GraphicsWidth(),GraphicsHeight() );

     Flip() ;
  }

  delete mgr; //<---------- Hangs on destruction!
  delete openAIF;

  FreeEntity(videotexture);
  FreeEntity(camera);
  FreeWorld(world);

  //Set gameState to 2 (main Menu)
  gState = 2;
  return;
}

 

Both Paramecij and Niosop's code I've found destroys the manager (and everything else) by calling Terminate() and exiting the app, but I need the game to continue running after playing the intro video :) .

 

Any thoughts on why it might hang?

 

Thanks in advance!

Press any key to continue...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...