我有基于DirectX的应用程序.最近我发现Now()函数在从我的图形引擎的主循环中调用时返回错误的值.它在引擎初始化之前调用一个值,在启动图形时在我的应用程序中调用时给出不同的值(通常在2-3分钟后退或向前).
我发现该Now()函数是Windows API GetLocalTime()函数的包装器.任何人都可以指出什么会影响这个函数的返回值?我timeGetTime()在我的应用程序的主循环中大量使用函数,它可能是问题的根源吗?另外我需要CheckSyncronize()在主循环中使用函数...
有任何想法吗?我的线索...... :(
主循环的代码:
procedure Td2dCore.System_Run;
var
l_Msg: TMsg;
l_Point: TPoint;
l_Rect : TRect;
l_Finish: Boolean;
begin
if f_WHandle = 0 then
begin
System_Log('Engine was not started!');
Exit;
end;
if not Assigned(f_OnFrame) then
begin
System_Log('Frame function is not assigned!');
Exit;
end;
// MAIN LOOP
l_Finish := False;
while not l_Finish do
begin
// dispatch messages
if PeekMessage(l_Msg, 0, 0, 0, PM_REMOVE) then
begin
if l_Msg.message = WM_QUIT then …Run Code Online (Sandbox Code Playgroud) 我创建了我的第一个动态壁纸,在一个单独的线程中实现绘图.所以现在我有了一个WallpaperService和我的WallpaperPainter来完成这项工作.问题是,我得到一个IllegalArgumentException在unlockCanvasAndPost某些设备上的方法(三星Note是一个).我已经阅读了所有可以找到的建议,但无法修复该错误.看起来像unlockCanvasAndPost表面被破坏时被调用,因此画布无效.以下是代码的基本部分:
在壁纸服务:
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
super.onSurfaceChanged(holder, format, width, height);
painting.setSurfaceSize(width, height);
}
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
super.onSurfaceCreated(holder);
painting.start();
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
painting.stopPainting();
while (retry) {
try {
painting.join();
retry = false;
} catch (InterruptedException e) { }
}
super.onSurfaceDestroyed(holder);
}
Run Code Online (Sandbox Code Playgroud)
在绘画线程中:
public void stopPainting() {
this.run = false;
synchronized(this) {
this.notify();
}
}
public void …Run Code Online (Sandbox Code Playgroud)